99 *
1010 * Implement a simple LinkedList
1111 * You will need to create a LinkedListNode class, which represents each item/node in the linked list
12+ * Assume that the elements in the linked list are all of type int
1213 * Required functionality...
1314 * - head(): get head of list
1415 * - tail(): get tail of list
@@ -31,6 +32,7 @@ public LinkedList() {
3132
3233 /**
3334 * constructor with first value
35+ * @param value first element in the linked list
3436 */
3537 public LinkedList (int value ) {
3638 // create first node
@@ -39,15 +41,15 @@ public LinkedList(int value) {
3941
4042 /**
4143 * get head of Linked List
42- * @return
44+ * @return first element of the linked list
4345 */
4446 public LinkedListNode head () {
4547 return this .head ;
4648 }
4749
4850 /**
4951 * traverse and get tail of linked list
50- * @return
52+ * @return last element of the linked list
5153 */
5254 public LinkedListNode tail () {
5355 LinkedListNode current = head ;
@@ -62,6 +64,7 @@ public LinkedListNode tail() {
6264
6365 /**
6466 * add new element (node) to linked list
67+ * @param value element to add to the end of the linked list
6568 */
6669 public void add (int value ) {
6770 LinkedListNode tail = tail ();
@@ -73,17 +76,16 @@ public void add(int value) {
7376 }
7477
7578 /**
76- * push (add to head of linkedlist)
77- * @return
79+ * push (add element to head of linkedlist)
7880 */
7981 public void push (int value ) {
8082 LinkedListNode newHead = new LinkedListNode (value , head );
8183 head = newHead ;
8284 }
8385
8486 /**
85- * pop (remove head of linkedlist)
86- * @return
87+ * pop (remove and return head of linkedlist)
88+ * @return the node that was removed
8789 */
8890 public LinkedListNode pop () {
8991 LinkedListNode popped = head ;
@@ -92,8 +94,8 @@ public LinkedListNode pop() {
9294 }
9395
9496 /**
95- * to String
96- * @return
97+ * Returns a String version of the LinkedList
98+ * @return a String version of the LinkedList
9799 */
98100 @ Override
99101 public String toString () {
@@ -116,11 +118,19 @@ class Node {
116118 private UUID ID ;
117119 private int value ;
118120
121+ /**
122+ * Constructs a list node with the given value
123+ * @param value the value stored in this Node
124+ */
119125 public Node (int value ) {
120126 this .ID = UUID .randomUUID ();
121127 this .value = value ;
122128 }
123129
130+ /**
131+ * Returns the value of this Node
132+ * @return the value of this Node
133+ */
124134 public int value () {
125135 return this .value ;
126136 }
@@ -130,15 +140,28 @@ class LinkedListNode extends Node {
130140
131141 private LinkedListNode next ;
132142
143+ /**
144+ * Constructs a LinkedListNode
145+ * @param value the value stored in this node
146+ * @param next the next node
147+ */
133148 public LinkedListNode (int value , LinkedListNode next ) {
134149 super (value );
135150 this .next = next ;
136151 }
137152
153+ /**
154+ * Returns the next node
155+ * @return the next node
156+ */
138157 public LinkedListNode next () {
139158 return this .next ;
140159 }
141160
161+ /**
162+ * Sets the next node
163+ * @param next the next node
164+ */
142165 public void setNext (LinkedListNode next ) {
143166 this .next = next ;
144167 return ;
0 commit comments