Skip to content

Commit 2b5e02d

Browse files
committed
Merge branch 'master' of https://github.com/ArmeetJatyani/java
2 parents 9ac5b2d + e4e6db9 commit 2b5e02d

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*
77
* Implement a simple LinkedList
88
* You will need to create a LinkedListNode class, which represents each item/node in the linked list
9+
* Assume that the elements in the linked list are all of type int
910
* Required functionality...
1011
* - head(): get head of list
1112
* - tail(): get tail of list

src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public LinkedListNode tail() {
5454
if (current == null) return null;
5555

5656
while (current.getNext() != null) {
57-
current = current.getNext();
57+
current = current.next();
5858
}
5959

6060
return current;
@@ -67,10 +67,10 @@ public void add(int value) {
6767
LinkedListNode tail = tail();
6868
if (tail == null) {
6969
head = new LinkedListNode(value, null);
70-
return;
71-
}
70+
} else {
7271

73-
tail.setNext(new LinkedListNode(value, null));
72+
tail.setNext(new LinkedListNode(value, null));
73+
}
7474
}
7575

7676
/**
@@ -88,7 +88,7 @@ public void push(int value) {
8888
*/
8989
public LinkedListNode pop() {
9090
LinkedListNode popped = head;
91-
head = head.getNext();
91+
head = head.next();
9292
return popped;
9393
}
9494

@@ -102,10 +102,11 @@ public String toString() {
102102
LinkedListNode current = head;
103103
if (current == null) return null;
104104
do {
105-
list += Integer.toString(current.getValue()) + ", ";
105+
list += Integer.toString(current.value()) + ", ";
106106
current = current.getNext();
107107
} while (current != null);
108108

109+
// Remove trailing comma and space after last list element
109110
list = list.substring(0, list.length() - 2);
110111
return list + "]";
111112
}

src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void main(String[] args) {
2020
// define a double variable on line 21
2121

2222

23-
// define a boolean variable on line 24 (Hint: true/false) on line 24
23+
// define a boolean variable on line 24 (Hint: true/false)
2424

2525

2626
// define a character variable on line 27
@@ -31,4 +31,4 @@ public static void main(String[] args) {
3131

3232
}
3333
}
34-
34+

src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ public static void main(String[] args) {
1717
// define an integer variable called numApples with value 24 (line 18)
1818
int numApples = 24;
1919

20-
// print out number of oranges, output: "I have 10 oranges." (line 21)
20+
// print out number of oranges using variables, output: "I have 10 oranges." (line 21)
2121
System.out.println("I have " + numOranges + " oranges.");
2222

23-
// print out number of apples, output: "I have 24 apples." (line 24)
23+
// print out number of apples using variables, output: "I have 24 apples." (line 24)
2424
System.out.println("I have " + numApples + " apples.");
2525

2626
}
2727
}
28-
28+

src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void main(String[] args) {
2020
// define a double variable on line 21
2121
double decimal = 23.2352536d;
2222

23-
// define a boolean variable on line 24 (Hint: true/false) on line 24
23+
// define a boolean variable on line 24 (Hint: true/false)
2424
double dogsOut = true; // the dogs are out :)
2525

2626
// define a character variable on line 27
@@ -31,4 +31,4 @@ public static void main(String[] args) {
3131

3232
}
3333
}
34-
34+

0 commit comments

Comments
 (0)