Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
|
|
@ -0,0 +1,45 @@
|
|||
Node = {"item": null, "next": null}
|
||||
Node.init = function(item)
|
||||
node = new Node
|
||||
node.item = item
|
||||
return node
|
||||
end function
|
||||
|
||||
LinkedList = {"head": null, "tail": null}
|
||||
LinkedList.append = function(item)
|
||||
newNode = Node.init(item)
|
||||
if self.head == null then
|
||||
self.head = newNode
|
||||
self.tail = self.head
|
||||
else
|
||||
self.tail.next = newNode
|
||||
self.tail = self.tail.next
|
||||
end if
|
||||
end function
|
||||
|
||||
LinkedList.insert = function(aftItem, item)
|
||||
newNode = Node.init(item)
|
||||
cursor = self.head
|
||||
while cursor.item != aftItem
|
||||
print cursor.item
|
||||
cursor = cursor.next
|
||||
end while
|
||||
newNode.next = cursor.next
|
||||
cursor.next = newNode
|
||||
end function
|
||||
|
||||
LinkedList.traverse = function
|
||||
cursor = self.head
|
||||
while cursor != null
|
||||
// do stuff
|
||||
print cursor.item
|
||||
cursor = cursor.next
|
||||
end while
|
||||
end function
|
||||
|
||||
test = new LinkedList
|
||||
test.append("A")
|
||||
test.append("B")
|
||||
test.insert("A","C")
|
||||
|
||||
test.traverse
|
||||
Loading…
Add table
Add a link
Reference in a new issue