File tree 1 file changed +20
-7
lines changed
src/data-structures/linked-list
1 file changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,20 @@ Add(value)
28
28
end if
29
29
end Add
30
30
```
31
-
31
+
32
+ ```
33
+ Prepend(value)
34
+ Pre: value is the value to add to the list
35
+ Post: value has been placed at the head of the list
36
+ n ← node(value)
37
+ n.next ← head
38
+ head ← n
39
+ if tail = ø
40
+ tail ← n
41
+ end
42
+ end Prepend
43
+ ```
44
+
32
45
### 搜索
33
46
34
47
``` text
@@ -67,10 +80,10 @@ Remove(head, value)
67
80
end if
68
81
return true
69
82
end if
70
- while n.next = ø and n.next.value = value
83
+ while n.next ! = ø and n.next.value ! = value
71
84
n ← n.next
72
85
end while
73
- if n.next = ø
86
+ if n.next ! = ø
74
87
if n.next = tail
75
88
tail ← n
76
89
end if
@@ -88,7 +101,7 @@ Traverse(head)
88
101
Pre: head is the head node in the list
89
102
Post: the items in the list have been traversed
90
103
n ← head
91
- while n = 0
104
+ while n ! = 0
92
105
yield n.value
93
106
n ← n.next
94
107
end while
@@ -101,11 +114,11 @@ end Traverse
101
114
ReverseTraversal(head, tail)
102
115
Pre: head and tail belong to the same list
103
116
Post: the items in the list have been traversed in reverse order
104
- if tail = ø
117
+ if tail ! = ø
105
118
curr ← tail
106
- while curr = head
119
+ while curr ! = head
107
120
prev ← head
108
- while prev.next = curr
121
+ while prev.next ! = curr
109
122
prev ← prev.next
110
123
end while
111
124
yield curr.value
You can’t perform that action at this time.
0 commit comments