Skip to content

Commit 0acbab5

Browse files
author
Kay Hudson
committed
Add comments for the classes.
1 parent d4dc3da commit 0acbab5

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

src/main/java/com/galvanize/LinkedList.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
/*
2+
Linked List
3+
4+
A linked list is a data structure that stores data sequentially by
5+
linking each item in the list to the next. It has the following properties:
6+
7+
- head: the first item in the list
8+
- tail (optional) : last item in the list
9+
10+
It's made up of items called Nodes, which contain 2 pieces of information:
11+
12+
- value: any type or you can restrict to specific types
13+
- next: a reference to the next item in the list
14+
15+
Nodes are usually added to the end of the list. Operations include:
16+
17+
- Add node
18+
- Remove node
19+
- Find a node
20+
For example, suppose you have a LinkedList of numbers. It might look
21+
like so:
22+
23+
* [] represents the 'value' attribute
24+
* -> represents the 'next' attribute
25+
* Together, []-> represents a Node
26+
27+
[100]-> [200]-> [300]-> null
28+
29+
The Node with value 100 is the head. The Node with value 300 is the
30+
tail. Note how the tail points to nothing. Therefore null signifies
31+
the end of the list.
32+
*/
133
package com.galvanize;
234

335
public class LinkedList {

src/main/java/com/galvanize/Node.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*
2+
Node
3+
4+
Nodes are the individual units contained in a data structure.
5+
6+
A node is a value object, representing any type of value and
7+
providing a reference to the next node.
8+
*/
19
package com.galvanize;
210

311
import java.util.Objects;

src/main/java/com/galvanize/Stack.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
package com.galvanize;
22

33
public class Stack {
4-
public boolean empty;
54
public Node top;
65
private int size;
76

87
public Stack() {
9-
this.empty = true;
108
this.size = 0;
119
}
1210

1311
public int count() {
1412
return size;
1513
}
1614

15+
public boolean isEmpty() {
16+
return this.count() == 0;
17+
}
18+
1719
public void push(Node item) {
1820
if (top == null) {
1921
top = item;
20-
this.empty = false;
2122
} else {
2223
item.setNext(top);
2324
top = item;

src/test/java/StackTestCase.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ void setUp() {
1313
stack = new Stack();
1414
}
1515

16+
@Test
17+
void testStackEmptyTrue() {
18+
assertTrue(stack.isEmpty());
19+
}
20+
1621
@Test
1722
void testStackPushNode () {
1823
stack.push(new Node(100));
@@ -42,11 +47,6 @@ void testStackPeekReturnsTopNode() {
4247
assertEquals(topItem, peekItem);
4348
}
4449

45-
@Test
46-
void testStackEmptyTrue() {
47-
assertTrue(stack.empty);
48-
}
49-
5050
@Test
5151
void testNodesEqual() {
5252
Node treeNode = new Node("Tree");

0 commit comments

Comments
 (0)