Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ListNode.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
public class ListNode {

public int data;
public ListNode next;

public ListNode(int data) {
this.data = data;
}
}
51 changes: 51 additions & 0 deletions src/Practice.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
public class Practice {
public static void main(String[] args) {
ListNode head = new ListNode(14);
ListNode MySeven = new ListNode(7);

// this sets head.next to MySeven value.
head.next = MySeven;

// this creates a new Node with a value of 28 which is stored in MySeven.next etc...
MySeven.next = new ListNode(28);
head.next.next = new ListNode(32);
head.next.next.next = new ListNode(23);



// int result = tailData(head);
// System.out.println(result);

head = removeSecondNode(head);

ListNode current = head;
while(current != null) {
System.out.println(current.data);
current = current.next;
}

// System.out.println(head);

// ListNode current = head;
// int total = 0;
// while(current != null) {
// total += current.data;
// current = current.next;
// }
// System.out.println(total);
// }
}

public static int tailData(ListNode head) {
if(head == null) return -1;

ListNode current = head;

while(current.next != null) {
current = current.next;
}
return current.data;
}
public static ListNode removeSecondNode(ListNode head) {

head.next = head.next.next;

return head;

}
}