From af4f2b2586f4206af69f91ca648da93bf868bebb Mon Sep 17 00:00:00 2001 From: ryanrmills Date: Mon, 12 May 2025 11:37:01 -0700 Subject: [PATCH 1/2] livecode commit 1 --- src/ListNode.java | 5 +++++ src/Practice.java | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/ListNode.java b/src/ListNode.java index dd6028c..d1f8ad1 100644 --- a/src/ListNode.java +++ b/src/ListNode.java @@ -1,3 +1,8 @@ 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..45a9e8f 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -1,5 +1,24 @@ public class Practice { public static void main(String[] args) { - + ListNode head = new ListNode(4); + 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.data); + System.out.println(head.next.data); + + ListNode current = head; + + while (current != null){ + System.out.println(current.data); + + current = current.next; + } + } } From d9ae18e481f4fa887fb78d412d95a326c5396e2b Mon Sep 17 00:00:00 2001 From: ryanrmills Date: Wed, 14 May 2025 11:04:48 -0700 Subject: [PATCH 2/2] message --- src/Practice.java | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index 45a9e8f..33d4248 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -9,16 +9,41 @@ public static void main(String[] args) { head.next.next.next = new ListNode(32); head.next.next.next.next = new ListNode(23); - System.out.println(head.data); - System.out.println(head.next.data); + System.out.println(); + System.out.println(); ListNode current = head; + head = removeSecondNode(head); + + while (current != null){ System.out.println(current.data); current = current.next; } + // System.out.println(total); + + } + + public static int mystery(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; } }