diff --git a/src/ListNode.java b/src/ListNode.java index dd6028c..187ecb8 100644 --- a/src/ListNode.java +++ b/src/ListNode.java @@ -1,3 +1,9 @@ public class ListNode { - + public int data; + public ListNode next; + + public ListNode(int data) { + this.data = data; + } + } \ No newline at end of file diff --git a/src/Practice.java b/src/Practice.java index 34a2f8d..295060d 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -1,5 +1,55 @@ public class Practice { public static void main(String[] args) { - + ListNode head = new ListNode(14); + ListNode mySeven = new ListNode(7); + + head.next = mySeven; + + mySeven.next = new ListNode(28); + head.next.next.next = new ListNode(32); + head.next.next.next.next = new ListNode(23); + + System.out.println(); + + head = removeSecondNode(head); + ListNode current = head; + while (current != null) { + System.out.println(current.data); + current = current.next; + } + // int result = tailData(head); + // System.out.println(result); + // System.out.println(head); + + // ListNode current = head; + // int total = 0; + // while (current != null) { + // // System.out.println(current.data); + // 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; + + ListNode current = head.next; + head.next = current.next; + + return head; } }