Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,20 @@
|
|||
class NodeList {
|
||||
private enum Flag { FRONT }
|
||||
private ListNode head
|
||||
void insert(value, insertionPoint=Flag.FRONT) {
|
||||
if (insertionPoint == Flag.FRONT) {
|
||||
head = new ListNode(payload: value, next: head)
|
||||
} else {
|
||||
def node = head
|
||||
while (node.payload != insertionPoint) {
|
||||
node = node.next
|
||||
if (node == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Insertion point ${afterValue} not already contained in list")
|
||||
}
|
||||
}
|
||||
node.next = new ListNode(payload:value, next:node.next)
|
||||
}
|
||||
}
|
||||
String toString() { "${head}" }
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
def list = new NodeList()
|
||||
list.insert('B')
|
||||
list.insert('A')
|
||||
println list
|
||||
|
||||
list.insert('C', 'A')
|
||||
println list
|
||||
Loading…
Add table
Add a link
Reference in a new issue