From e84f16e69625d0a079ba7fd41e94328a33669add Mon Sep 17 00:00:00 2001 From: AlexandrBalan <85966686+AlexandrBalan@users.noreply.github.com> Date: Mon, 11 May 2026 10:44:01 -0700 Subject: [PATCH 1/4] livecode during class, created myNode and anotherNode, also linked them together and point to each other. --- src/ListNode.java | 3 ++- src/Practice.java | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ListNode.java b/src/ListNode.java index dd6028c..8293484 100644 --- a/src/ListNode.java +++ b/src/ListNode.java @@ -1,3 +1,4 @@ public class ListNode { - + public char data; + public ListNode next; } \ No newline at end of file diff --git a/src/Practice.java b/src/Practice.java index 34a2f8d..a409676 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -1,5 +1,19 @@ +import java.util.LinkedList; + public class Practice { public static void main(String[] args) { - + ListNode myNode = new ListNode(); + + myNode.data = 'x'; + // System.out.println(myNode.data); + + ListNode anotherNode = new ListNode(); + + anotherNode.data = 't'; + + myNode.next = anotherNode; + + // System.out.println(myNode.data); + // System.out.println(anotherNode.data); } } From afcdf8fa50ad26f5bf4567aded1f9b631b90c995 Mon Sep 17 00:00:00 2001 From: AlexandrBalan <85966686+AlexandrBalan@users.noreply.github.com> Date: Mon, 11 May 2026 11:36:40 -0700 Subject: [PATCH 2/4] developed a linkedlist with variety of different letters. --- src/Practice.java | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/Practice.java b/src/Practice.java index a409676..674c382 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -13,7 +13,48 @@ public static void main(String[] args) { myNode.next = anotherNode; + ListNode moreNode = new ListNode(); + moreNode.data = 'r'; + + anotherNode.next = moreNode; + + ListNode coolNode = new ListNode(); + coolNode.data = 'w'; + + coolNode.next = myNode; + + + ListNode extra = moreNode; + moreNode.data = 'e'; + + + //added a new one myself into the list. + ListNode hello = new ListNode(); + hello.data = 'x'; + extra.next = hello; + + printList(coolNode); + // System.out.println(myNode.next.next.data); + // System.out.println(myNode.next.data); // System.out.println(myNode.data); // System.out.println(anotherNode.data); } + + public static void printList(ListNode head) { + //starting from head + //print all data in list in order + + //keep track of current, starting at head + //until end of list + // //print out data at current + // //move current to the next node + + ListNode current = head; + + while(current != null) { + System.out.println(current.data); + + current = current.next; + } + } } From 69537b199e0521f6328286a8ea318b0458663614 Mon Sep 17 00:00:00 2001 From: AlexandrBalan <85966686+AlexandrBalan@users.noreply.github.com> Date: Mon, 11 May 2026 11:47:22 -0700 Subject: [PATCH 3/4] finished the live coding assignment during class time --- src/Practice.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Practice.java b/src/Practice.java index 674c382..c6d878b 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -34,6 +34,12 @@ public static void main(String[] args) { extra.next = hello; printList(coolNode); + + int xCount = countX(coolNode); + + System.out.println(xCount); + + // System.out.println(myNode.next.next.data); // System.out.println(myNode.next.data); // System.out.println(myNode.data); @@ -57,4 +63,20 @@ public static void printList(ListNode head) { current = current.next; } } + //this should count how many nodes hold an x + public static int countX(ListNode head) { + ListNode current = head; + int counter = 0; + + while(current != null) { + if(current.data == 'x') { + counter++; + } + + current = current.next; + } + + return counter; + + } } From f212c6bf51c9520d424cdd091357c2c7e0ea5893 Mon Sep 17 00:00:00 2001 From: AlexandrBalan <85966686+AlexandrBalan@users.noreply.github.com> Date: Wed, 13 May 2026 11:18:27 -0700 Subject: [PATCH 4/4] followed along in class livecoding --- src/Practice.java | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index c6d878b..dfade41 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -14,7 +14,7 @@ public static void main(String[] args) { myNode.next = anotherNode; ListNode moreNode = new ListNode(); - moreNode.data = 'r'; + moreNode.data = 'e'; anotherNode.next = moreNode; @@ -33,17 +33,21 @@ public static void main(String[] args) { hello.data = 'x'; extra.next = hello; - printList(coolNode); + // printList(coolNode); - int xCount = countX(coolNode); + // int xCount = countX(coolNode); - System.out.println(xCount); + // System.out.println(xCount); // System.out.println(myNode.next.next.data); // System.out.println(myNode.next.data); // System.out.println(myNode.data); // System.out.println(anotherNode.data); + + ListNode newHead = removeAt(coolNode, 0); + + printList(newHead); } public static void printList(ListNode head) { @@ -79,4 +83,29 @@ public static int countX(ListNode head) { return counter; } + + + //remove the node at removeIndex, and then return the head of the list. + + //Example: + + //e --> t --> k --> y + + // removeIndex 2 + //e --> t --> y + public static ListNode removeAt(ListNode head, int removeIndex) { + if(removeIndex == 0) { + return head.next; + } + + ListNode current = head; + + for(int i = 0; i < removeIndex - 1; i++) { + current = current.next; + } + + current.next = current.next.next; + + return head; + } }