@@ -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.
0 commit comments