-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from mjp41/0-linked-lists
Recursive linked list and smaller fixes
- Loading branch information
Showing
10 changed files
with
158 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# For now separate | ||
def insert(node, item): | ||
if node.next == None: | ||
node.next = {} | ||
node.next.data = item | ||
node.next.prev = node | ||
else: | ||
insert(node.next, item) | ||
|
||
def contains(node, item): | ||
if node.data == item: | ||
return True | ||
if node.next == None: | ||
return False | ||
return find(node.next, item) | ||
|
||
def remove(node, item): | ||
if node.data == item: | ||
node.prev.next = node.next | ||
if node.next != None: | ||
node.next.prev = node.prev | ||
return True | ||
if node.next == None: | ||
return False | ||
return remove(node.next, item) | ||
|
||
def new_list(): | ||
list = {} | ||
list.head = {} | ||
return list | ||
|
||
list = new_list() | ||
|
||
# Required to not leak memory | ||
region list | ||
|
||
value = "x" | ||
|
||
# Dyrona doesn't freeze shared objects automatically (yet) | ||
proto = value["__proto__"] | ||
freeze proto | ||
drop proto | ||
|
||
insert(list.head, {}) | ||
insert(list.head, {}) | ||
insert(list.head, value) | ||
insert(list.head, {}) | ||
remove(list.head, value) | ||
|
||
drop value | ||
drop list |