Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

28
LINES

< > BotCompany Repo | #1032878 // MinimalChain - singly-linked cons list (like Chain) but without the size field

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3832L/22K).

1  
sclass MinimalChain<A> implements Iterable<A> {
2  
  A element;
3  
  MinimalChain<A> next;
4  
5  
  *() {}
6  
  *(A *element) {}
7  
  *(A *element, MinimalChain<A> *next) {}
8  
  
9  
  toString { ret str(toList()); }
10  
  
11  
  ArrayList<A> toList() {
12  
    new ArrayList<A> l;
13  
    MinimalChain<A> c = this;
14  
    while (c != null) {
15  
      l.add(c.element);
16  
      c = c.next;
17  
    }
18  
    ret l;
19  
  }
20  
  
21  
  void setElement(A a) { element = a; }
22  
  void setNext(MinimalChain<A> next) { this.next = next; }
23  
  
24  
  // TODO: optimize
25  
  public Iterator<A> iterator() { ret toList().iterator(); }
26  
  
27  
  A get() { ret element; }
28  
}

Author comment

Began life as a copy of #1027968

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1032878
Snippet name: MinimalChain - singly-linked cons list (like Chain) but without the size field
Eternal ID of this version: #1032878/7
Text MD5: f20aba4f9c34fc195151af3aa454f80b
Transpilation MD5: 42b739a908438f40818dbba996c587a9
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-10 20:42:50
Source code size: 607 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 89 / 1216
Version history: 6 change(s)
Referenced in: [show references]