Skip to content

Commit fa64011

Browse files
committed
Update docs
1 parent fa9a3c1 commit fa64011

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

data_structures/linked_list/doubly_linked_list.dart

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class DoubleLinkedList<T> extends Iterable<T> {
1919
@override
2020
Iterator<T> get iterator => _LinkedListIterator<T>(this._head);
2121

22+
/// Adding a node to the end of the Doubly Linked List.
23+
///
2224
/// Pseudocode:
2325
/// - Create a new node with the value passed to the function.
2426
/// - If the list is empty, set the head and tail to be the newly created node.
@@ -44,6 +46,8 @@ class DoubleLinkedList<T> extends Iterable<T> {
4446
return this;
4547
}
4648

49+
/// Removing a node from the end of the Doubly Linked List.
50+
///
4751
/// Pseudocode:
4852
/// - If the list is empty, return null.
4953
/// - Store the current tail in a variable to return later.
@@ -69,6 +73,8 @@ class DoubleLinkedList<T> extends Iterable<T> {
6973
return poppedNode.value;
7074
}
7175

76+
/// Removing a node from the beginning of the Doubly Linked List.
77+
///
7278
/// Pseudocode:
7379
/// - If the list is empty, return null.
7480
/// - Store the current head in a variable to return later.
@@ -94,6 +100,8 @@ class DoubleLinkedList<T> extends Iterable<T> {
94100
return oldHead.value;
95101
}
96102

103+
/// Adding a node to the beginning of the Doubly Linked List.
104+
///
97105
/// Pseudocode:
98106
/// - This function should accept a value.
99107
/// - Create a new node using the value passed to the function.
@@ -120,10 +128,8 @@ class DoubleLinkedList<T> extends Iterable<T> {
120128
return this;
121129
}
122130

123-
T? get(int index) {
124-
return _getNodeAtIndex(index)?.value;
125-
}
126-
131+
/// Accessing a node in a Doubly Linked List by its position.
132+
///
127133
/// Pseudocode:
128134
/// - If the index is less than 0 or greater or equal to the length, return null
129135
/// - If the index is less than or equal to half the length of the list:
@@ -132,6 +138,10 @@ class DoubleLinkedList<T> extends Iterable<T> {
132138
/// - If the index is greater than half the length of the list:
133139
/// - Loop through the list starting from the tail and loop towards the middle
134140
/// - Return the node once it is found
141+
T? get(int index) {
142+
return _getNodeAtIndex(index)?.value;
143+
}
144+
135145
Node<T>? _getNodeAtIndex(int index) {
136146
if (index < 0 || index >= _length) return null;
137147

@@ -152,6 +162,8 @@ class DoubleLinkedList<T> extends Iterable<T> {
152162
return current;
153163
}
154164

165+
/// Replacing the value of a node to the in a Doubly Linked List.
166+
///
155167
/// Pseudocode:
156168
/// - This function should accept a value and an index.
157169
/// - Use your get function to find the specific node.
@@ -166,6 +178,8 @@ class DoubleLinkedList<T> extends Iterable<T> {
166178
return false;
167179
}
168180

181+
/// Adding a node in a Doubly Linked List by a certain position.
182+
///
169183
/// Pseudocode:
170184
/// - If the index is less than zero or greater than the length, return false.
171185
/// - If the index is the same as the length, push a new node to the end of the list.
@@ -195,6 +209,8 @@ class DoubleLinkedList<T> extends Iterable<T> {
195209
return true;
196210
}
197211

212+
/// Removing a node in a Doubly Linked List by a certain position.
213+
///
198214
/// Pseudocode:
199215
/// - If the index is less than zero or greater than or equal to the length, return null.
200216
/// - If the index is the same as the length-1, return pop.

data_structures/linked_list/linked_list.dart

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class LinkedList<T> extends Iterable<T> {
1818
@override
1919
Iterator<T> get iterator => _LinkedListIterator<T>(this._head);
2020

21+
/// Adding a new node to the end of the Linked List.
22+
///
2123
/// Pseudocode:
2224
/// - This function should accept a value.
2325
/// - Create a new node using the value passed to the function.
@@ -42,6 +44,8 @@ class LinkedList<T> extends Iterable<T> {
4244
return this;
4345
}
4446

47+
/// Removing a node from the end of the Linked List.
48+
///
4549
/// Pseudocode:
4650
/// - If the list is empty, return null.
4751
/// - If the length is 1, set the head and tail to null.
@@ -72,6 +76,8 @@ class LinkedList<T> extends Iterable<T> {
7276
return poppedNode.value;
7377
}
7478

79+
/// Removing a node from the beginning of the Linked List.
80+
///
7581
/// Pseudocode:
7682
/// - If the list is empty, return null.
7783
/// - Store the current head in a variable to return later.
@@ -95,6 +101,8 @@ class LinkedList<T> extends Iterable<T> {
95101
return oldHead.value;
96102
}
97103

104+
/// Adding a new node to the beginning of the Linked List.
105+
///
98106
/// Pseudocode:
99107
/// - This function should accept a value.
100108
/// - Create a new node using the value passed to the function.
@@ -119,16 +127,18 @@ class LinkedList<T> extends Iterable<T> {
119127
return this;
120128
}
121129

122-
T? get(int index) {
123-
return _getNodeAtIndex(index)?.value;
124-
}
125-
130+
/// Retrieving a node by it's position in the Linked List.
131+
///
126132
/// Pseudocode:
127133
/// - This function should accept an index.
128134
/// - If the index is less than zero or greater than or equal to the length of the list, return null.
129135
/// - Otherwise:
130136
/// - Loop through the list until you reach the index.
131137
/// - Return the node at that specific index.
138+
T? get(int index) {
139+
return _getNodeAtIndex(index)?.value;
140+
}
141+
132142
Node<T>? _getNodeAtIndex(int index) {
133143
if (index < 0 || index >= _length) return null;
134144

@@ -139,6 +149,8 @@ class LinkedList<T> extends Iterable<T> {
139149
return current;
140150
}
141151

152+
/// Changing the value of a node based on it's position in the Linked List.
153+
///
142154
/// Pseudocode:
143155
/// - This function should accept a value and an index.
144156
/// - Use your get function to find the specific node.
@@ -153,6 +165,8 @@ class LinkedList<T> extends Iterable<T> {
153165
return false;
154166
}
155167

168+
/// Adding a node to the Linked List at a specific position.
169+
///
156170
/// Pseudocode:
157171
/// - If the index is less than zero or greater than the length, return false.
158172
/// - If the index is the same as the length, push a new node to the end of the list.
@@ -180,6 +194,8 @@ class LinkedList<T> extends Iterable<T> {
180194
return true;
181195
}
182196

197+
/// Removing a node from the Linked List at a specific position.
198+
///
183199
/// Pseudocode:
184200
/// - If the index is less than zero or greater than or equal to the length, return null.
185201
/// - If the index is the same as the length-1, return pop.
@@ -202,6 +218,8 @@ class LinkedList<T> extends Iterable<T> {
202218
return removedNode.value;
203219
}
204220

221+
/// Reversing the Linked List in place.
222+
///
205223
/// Pseudocode:
206224
/// - Swap the head and tail.
207225
/// - Create a variable called next.

data_structures/stack/linked_list_stack.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ class LinkedListStack<T> {
1818

1919
bool get isEmpty => size == 0;
2020

21-
/// Push from the start (head) same as the linked list's unShift. (to achieve constant time when popping)
21+
/// Add a value to the top of the stack.
22+
/// Pushing from the start (head) as the linked list's unShift. (to achieve constant time when popping)
23+
///
2224
/// Pseudocode:
2325
/// - The function should accept a value.
2426
/// - Create a new node with that value.
@@ -32,6 +34,9 @@ class LinkedListStack<T> {
3234
return ++_size;
3335
}
3436

37+
/// Remove a value from the top of the stack.
38+
/// Popping from the start too (head) same as the linked list's shift.
39+
///
3540
/// Pseudocode:
3641
/// - If the stack is empty, return null.
3742
/// - Create a temporary variable to store the head property in the stack.

0 commit comments

Comments
 (0)