From 8cc92d0bd494f33e734436fd3cc8018833c8b792 Mon Sep 17 00:00:00 2001 From: AmiyahJo <86239804+AmiyahJo@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:05:50 -0400 Subject: [PATCH 01/19] Create README.md Accidentally removed my work the 1st time by merging --- lesson_00/amiyahjones/README.md | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lesson_00/amiyahjones/README.md diff --git a/lesson_00/amiyahjones/README.md b/lesson_00/amiyahjones/README.md new file mode 100644 index 000000000..14fc62d70 --- /dev/null +++ b/lesson_00/amiyahjones/README.md @@ -0,0 +1,43 @@ +# Mya.README + ```Javascript +const Mya = class SoftwareEngineer { + intern(code, tools) { + self.code = Javascript, HTML, CSS, Java; + self.tools = React, Docker; + } +}; + +// Intrested in bringing ideas to life within a web browser. +// Learning how websites become quick, responsive, and accesssible to everyone. +``` + + + +### ☴ My work hours +9AM-5PM I'm an early bird and often begin the day with a head start of my work. Feel free to reach me by email during this time, and I'll get back to you as soon as I'm able! + +### What's the best way to communicate with me? .☘︎ ݁˖ +Private message through google chat works perfectly. Email works too as a follow up or if I happened to miss one of your messages. +> [!TIP] +> _In case I don't respond:_ Ping me again on google chat or send me another email! + +### I'd be happy to help you with ꒰ ﹍ ꒱ +* Code suggestions +* Explain or understand a code snippet +* Photos + design ideas + +## Extra ⓘ +* ✦ procreate artist ↓
+ - I like to combine my art and code together! + - In case you find me with my ipad, that's why +* visual learner
+* Jr Developer HS Intern for 4 years with Code Differently (youth program) +* No, I don't drink coffee. ~~Hot chocolate is my go to~~ + +> I'm the type of person that if you ask me a question and I don't know the answer, I'm gonna tell you that I don't know. But I bet you what, I know how to find the answer and I will find the answer.
- Will smith + + +###### // readme inspired by [Kaeti's repo][kaeti-repo] , code snippet inspired by [Thai Brega] + +[kaeti-repo]: https://github.com/kaeti/personal-readme +[Thai brega]: https://github.com/Thaiane/Thaiane From 50b18619d9de9203384f678c1e0eee84a70510a0 Mon Sep 17 00:00:00 2001 From: AmiyahJo <86239804+AmiyahJo@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:07:22 -0400 Subject: [PATCH 02/19] Delete lesson_00/amiyahjones/README.md --- lesson_00/amiyahjones/README.md | 43 --------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 lesson_00/amiyahjones/README.md diff --git a/lesson_00/amiyahjones/README.md b/lesson_00/amiyahjones/README.md deleted file mode 100644 index 14fc62d70..000000000 --- a/lesson_00/amiyahjones/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# Mya.README - ```Javascript -const Mya = class SoftwareEngineer { - intern(code, tools) { - self.code = Javascript, HTML, CSS, Java; - self.tools = React, Docker; - } -}; - -// Intrested in bringing ideas to life within a web browser. -// Learning how websites become quick, responsive, and accesssible to everyone. -``` - - - -### ☴ My work hours -9AM-5PM I'm an early bird and often begin the day with a head start of my work. Feel free to reach me by email during this time, and I'll get back to you as soon as I'm able! - -### What's the best way to communicate with me? .☘︎ ݁˖ -Private message through google chat works perfectly. Email works too as a follow up or if I happened to miss one of your messages. -> [!TIP] -> _In case I don't respond:_ Ping me again on google chat or send me another email! - -### I'd be happy to help you with ꒰ ﹍ ꒱ -* Code suggestions -* Explain or understand a code snippet -* Photos + design ideas - -## Extra ⓘ -* ✦ procreate artist ↓
- - I like to combine my art and code together! - - In case you find me with my ipad, that's why -* visual learner
-* Jr Developer HS Intern for 4 years with Code Differently (youth program) -* No, I don't drink coffee. ~~Hot chocolate is my go to~~ - -> I'm the type of person that if you ask me a question and I don't know the answer, I'm gonna tell you that I don't know. But I bet you what, I know how to find the answer and I will find the answer.
- Will smith - - -###### // readme inspired by [Kaeti's repo][kaeti-repo] , code snippet inspired by [Thai Brega] - -[kaeti-repo]: https://github.com/kaeti/personal-readme -[Thai brega]: https://github.com/Thaiane/Thaiane From 672ce73fe4d33608b1952b79aeda95eca91c92f8 Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Mon, 21 Oct 2024 20:44:33 +0000 Subject: [PATCH 03/19] feat: adds comments Breaking down the objective explained in a way for me to understand --- .../com/codedifferently/lesson12/Lesson12.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java index af7663e90..de21e2d62 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java @@ -8,5 +8,21 @@ public class Lesson12 { */ public String gameResult(ListNode head) { return null; + //make a linked list + + //create two variables to count points for "Odd" and "Even" + + // Check each pair of nodes (odd and even): + // compare their values + + // add a point to "Odd" if the odd-indexed node is higher + + //add a point to "Even" if the even-indexed node is higher + + // Decide the winner + // compare the points after going through both pairs + + // Return the name of the winning team or "Tie" if points are equal + } } From c03667fa376a9c675e46cd14150ef553021232b5 Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Mon, 21 Oct 2024 20:49:34 +0000 Subject: [PATCH 04/19] feat: adds code snippets pulled from the google slides to refrence what should be used --- .../java/com/codedifferently/lesson12/Lesson12.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java index de21e2d62..023855164 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java @@ -9,9 +9,13 @@ public class Lesson12 { public String gameResult(ListNode head) { return null; //make a linked list - + Queue queue = new LinkedList(); + //create two variables to count points for "Odd" and "Even" - + var Odd = new Stack(); + var Even = new Stack(); + // Loop through the linked list to get pairs (so two nodes at a time) + // Check each pair of nodes (odd and even): // compare their values @@ -21,7 +25,7 @@ public String gameResult(ListNode head) { // Decide the winner // compare the points after going through both pairs - + // Return the name of the winning team or "Tie" if points are equal } From 7e397381cc03be5a723847e55d79895eb05be98d Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Mon, 21 Oct 2024 20:51:09 +0000 Subject: [PATCH 05/19] feat: adds constraints --- .../main/java/com/codedifferently/lesson12/Lesson12.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java index 023855164..27aa1637e 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java @@ -15,7 +15,7 @@ public String gameResult(ListNode head) { var Odd = new Stack(); var Even = new Stack(); // Loop through the linked list to get pairs (so two nodes at a time) - + // Check each pair of nodes (odd and even): // compare their values @@ -30,3 +30,9 @@ public String gameResult(ListNode head) { } } + +// Constraints: +// The number of nodes in the list is in the range [2, 100]. +// The number of nodes in the list is even. 1 <= Node.val <= 100 +// The value of each odd-indexed node is odd. +// The value of each even-indexed node is even. From 710b3c1ebe83c81129b1ce3213e0a75239f2732b Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Mon, 21 Oct 2024 20:52:45 +0000 Subject: [PATCH 06/19] fix: variables "even" and "odd" turned to integers --- .../src/main/java/com/codedifferently/lesson12/Lesson12.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java index 27aa1637e..7f2972775 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java @@ -12,8 +12,8 @@ public String gameResult(ListNode head) { Queue queue = new LinkedList(); //create two variables to count points for "Odd" and "Even" - var Odd = new Stack(); - var Even = new Stack(); + int Odd = 0; + int Even = 0; // Loop through the linked list to get pairs (so two nodes at a time) // Check each pair of nodes (odd and even): From c0545ad66dd7259785cadce211a95ce33f5cf787 Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Tue, 22 Oct 2024 12:51:36 +0000 Subject: [PATCH 07/19] feat: adds if else statement on whether one of the teams win or if its a tie --- .../com/codedifferently/lesson12/Lesson12.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java index 7f2972775..6b88e0dd6 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java @@ -1,5 +1,7 @@ package com.codedifferently.lesson12; +import java.util.Queue; + public class Lesson12 { /** @@ -7,7 +9,6 @@ public class Lesson12 { * https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game */ public String gameResult(ListNode head) { - return null; //make a linked list Queue queue = new LinkedList(); @@ -24,10 +25,15 @@ public String gameResult(ListNode head) { //add a point to "Even" if the even-indexed node is higher // Decide the winner - // compare the points after going through both pairs - - // Return the name of the winning team or "Tie" if points are equal - + // compare the points and choose the winner or tie + if (Odd > Even) { + return("Team odd wins!"); + } else if (Even > Odd){ + return("Team Even wins"); + } else { + return ("It's a tie"); + } + } } From eedad00508651589f4547c8b16b3fa94727ff065 Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Tue, 22 Oct 2024 13:17:09 +0000 Subject: [PATCH 08/19] feat: adds code to solve the problem --- .../codedifferently/lesson12/Lesson12.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java index 6b88e0dd6..37e814ca4 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java @@ -1,7 +1,5 @@ package com.codedifferently.lesson12; -import java.util.Queue; - public class Lesson12 { /** @@ -9,26 +7,31 @@ public class Lesson12 { * https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game */ public String gameResult(ListNode head) { - //make a linked list - Queue queue = new LinkedList(); - //create two variables to count points for "Odd" and "Even" - int Odd = 0; - int Even = 0; - // Loop through the linked list to get pairs (so two nodes at a time) + int oddPoints = 0; + int evenPoints = 0; + // Loop through the linked list to get pairs (so two nodes at a time) + ListNode current = head; // Check each pair of nodes (odd and even): // compare their values - - // add a point to "Odd" if the odd-indexed node is higher - - //add a point to "Even" if the even-indexed node is higher - + while (current != null && current.next != null) { + // add a point to "Even" if the odd-indexed node is higher + if (current.val < current.next.val){ + evenPoints++; + } + //add a point to "Odd" if the even-indexed node is higher + else if (current.val > current.next.val){ + oddPoints++; + } + + current = current.next.next; + } // Decide the winner // compare the points and choose the winner or tie - if (Odd > Even) { + if (oddPoints > evenPoints) { return("Team odd wins!"); - } else if (Even > Odd){ + } else if (evenPoints > oddPoints){ return("Team Even wins"); } else { return ("It's a tie"); @@ -40,5 +43,3 @@ public String gameResult(ListNode head) { // Constraints: // The number of nodes in the list is in the range [2, 100]. // The number of nodes in the list is even. 1 <= Node.val <= 100 -// The value of each odd-indexed node is odd. -// The value of each even-indexed node is even. From 7c6d0b143657cccc59ffea4721728d4f0854b668 Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Tue, 22 Oct 2024 13:24:06 +0000 Subject: [PATCH 09/19] fix: adding a point if one of the even or odd indexed node is higher --- .../com/codedifferently/lesson12/Lesson12.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java index 37e814ca4..4cd6deed6 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java @@ -16,27 +16,23 @@ public String gameResult(ListNode head) { // Check each pair of nodes (odd and even): // compare their values while (current != null && current.next != null) { - // add a point to "Even" if the odd-indexed node is higher - if (current.val < current.next.val){ + // add a point to "Even" if the odd-indexed node is higher and vice versa + if (current.val > current.next.val){ evenPoints++; - } - //add a point to "Odd" if the even-indexed node is higher - else if (current.val > current.next.val){ + } else if (current.val < current.next.val){ oddPoints++; } - current = current.next.next; } // Decide the winner // compare the points and choose the winner or tie if (oddPoints > evenPoints) { - return("Team odd wins!"); + return "Odd"; } else if (evenPoints > oddPoints){ - return("Team Even wins"); + return "Even"; } else { - return ("It's a tie"); - } - + return "Tie"; + } } } From 1fac40a204a4c3319619c3d26fcf9fc324e7e413 Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Tue, 22 Oct 2024 13:24:32 +0000 Subject: [PATCH 10/19] chore: remove constraints comments --- .../src/main/java/com/codedifferently/lesson12/Lesson12.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java index 4cd6deed6..75926880c 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java @@ -35,7 +35,3 @@ public String gameResult(ListNode head) { } } } - -// Constraints: -// The number of nodes in the list is in the range [2, 100]. -// The number of nodes in the list is even. 1 <= Node.val <= 100 From 59bfb07176e115e6b90cdda57e55b4297417420a Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Tue, 22 Oct 2024 13:25:40 +0000 Subject: [PATCH 11/19] chore: remove comments in lesson12.java file --- .../com/codedifferently/lesson12/Lesson12.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java index 75926880c..46522b8be 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java @@ -2,21 +2,14 @@ public class Lesson12 { - /** - * Provide the solution to LeetCode 3062 here: - * https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game - */ public String gameResult(ListNode head) { - //create two variables to count points for "Odd" and "Even" + int oddPoints = 0; int evenPoints = 0; - // Loop through the linked list to get pairs (so two nodes at a time) ListNode current = head; - // Check each pair of nodes (odd and even): - // compare their values - while (current != null && current.next != null) { - // add a point to "Even" if the odd-indexed node is higher and vice versa + + while (current != null && current.next != null) { if (current.val > current.next.val){ evenPoints++; } else if (current.val < current.next.val){ @@ -24,8 +17,7 @@ public String gameResult(ListNode head) { } current = current.next.next; } - // Decide the winner - // compare the points and choose the winner or tie + if (oddPoints > evenPoints) { return "Odd"; } else if (evenPoints > oddPoints){ From a08470d935e3a0a23aac4d097c3f6fb591d76067 Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Tue, 22 Oct 2024 14:07:36 +0000 Subject: [PATCH 12/19] feat: adds code in ListNode push method and boolean isEmpty --- .../src/main/java/com/codedifferently/lesson12/Stack.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java index 8444fceca..989d957f6 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java @@ -10,6 +10,9 @@ public Stack() { public void push(int value) { // Your code here + ListNode newNode = new ListNode(value); + newNode.next = top; + top = newNode; } public int pop() { @@ -21,6 +24,6 @@ public int peek() { } public boolean isEmpty() { - return true; + return top == null; } } From 7c37b675a1cddeb0884126137aa16167041e604e Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Tue, 22 Oct 2024 14:21:45 +0000 Subject: [PATCH 13/19] feat: add implementation to stack pop and push --- .../main/java/com/codedifferently/lesson12/Stack.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java index 989d957f6..5b48385e0 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java @@ -16,11 +16,18 @@ public void push(int value) { } public int pop() { - return 0; + if (top == null){ + //do stuff + } + return 1; } public int peek() { - return 0; + if(top == null){ + //do stuff + } + + return 1; } public boolean isEmpty() { From 9a74b59d8af88db937d8191e90e3d63af9d7a432 Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Tue, 22 Oct 2024 14:22:23 +0000 Subject: [PATCH 14/19] chore: spacing in peek method for Stack.java --- .../src/main/java/com/codedifferently/lesson12/Stack.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java index 5b48385e0..b24f86b73 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java @@ -25,8 +25,7 @@ public int pop() { public int peek() { if(top == null){ //do stuff - } - + } return 1; } From 77ecfc5e074aa6fd3b528847ac0f50964fbc68b4 Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Tue, 22 Oct 2024 14:55:49 +0000 Subject: [PATCH 15/19] fix: replace stack.java 'top == null' to isEmpty() for if statements --- .../src/main/java/com/codedifferently/lesson12/Stack.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java index b24f86b73..f52f930e0 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java @@ -16,14 +16,14 @@ public void push(int value) { } public int pop() { - if (top == null){ - //do stuff + if (isEmpty()){ + System.out.println("EMPTY"); } return 1; } public int peek() { - if(top == null){ + if(isEmpty()){ //do stuff } return 1; From 4700bdbf16ce3f69f697a8c14582a54c62823266 Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Tue, 22 Oct 2024 15:42:06 +0000 Subject: [PATCH 16/19] fix: Code rewrite in stack.java and an exception reccomended by vscode --- .../com/codedifferently/lesson12/Stack.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java index f52f930e0..da58062d0 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java @@ -1,5 +1,7 @@ package com.codedifferently.lesson12; +import java.util.EmptyStackException; + /** Implement the below Stack by providing code for the class methods. */ public class Stack { private ListNode top; @@ -16,17 +18,20 @@ public void push(int value) { } public int pop() { - if (isEmpty()){ - System.out.println("EMPTY"); + if (isEmpty()) { + return 0; + } else { + int value = top.val; + top = top.next; + return value; } - return 1; } public int peek() { - if(isEmpty()){ - //do stuff - } - return 1; + if (isEmpty()) { + throw new EmptyStackException(); + } + return top.val; } public boolean isEmpty() { From a2e4d6570be6ae50678aa7c83a09c6b9652cef06 Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Tue, 22 Oct 2024 15:43:24 +0000 Subject: [PATCH 17/19] fix: changed stack pop method uses an empty exception rather than return a value of 0 --- .../src/main/java/com/codedifferently/lesson12/Stack.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java index da58062d0..7e51af0e3 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java @@ -19,7 +19,7 @@ public void push(int value) { public int pop() { if (isEmpty()) { - return 0; + throw new EmptyStackException(); } else { int value = top.val; top = top.next; From a75ae55a42c86f4fd3dd7d11a798a58d768e7200 Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Tue, 22 Oct 2024 15:43:52 +0000 Subject: [PATCH 18/19] chore : remove comment --- .../src/main/java/com/codedifferently/lesson12/Stack.java | 1 - 1 file changed, 1 deletion(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java index 7e51af0e3..c5b7c1906 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java @@ -11,7 +11,6 @@ public Stack() { } public void push(int value) { - // Your code here ListNode newNode = new ListNode(value); newNode.next = top; top = newNode; From 7ac1c120e91b1f30bfcad9f75499b44aa70ada98 Mon Sep 17 00:00:00 2001 From: AmiyahJo Date: Tue, 22 Oct 2024 15:49:12 +0000 Subject: [PATCH 19/19] fix: githubs recoomendation to avoid violations --- .../codedifferently/lesson12/Lesson12.java | 28 +++++++++---------- .../com/codedifferently/lesson12/Stack.java | 8 +++--- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java index 46522b8be..f6a3b286a 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java @@ -9,21 +9,21 @@ public String gameResult(ListNode head) { ListNode current = head; - while (current != null && current.next != null) { - if (current.val > current.next.val){ - evenPoints++; - } else if (current.val < current.next.val){ - oddPoints++; - } - current = current.next.next; + while (current != null && current.next != null) { + if (current.val > current.next.val) { + evenPoints++; + } else if (current.val < current.next.val) { + oddPoints++; } + current = current.next.next; + } - if (oddPoints > evenPoints) { - return "Odd"; - } else if (evenPoints > oddPoints){ - return "Even"; - } else { - return "Tie"; - } + if (oddPoints > evenPoints) { + return "Odd"; + } else if (evenPoints > oddPoints) { + return "Even"; + } else { + return "Tie"; + } } } diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java index c5b7c1906..d2e84cfca 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java @@ -18,11 +18,11 @@ public void push(int value) { public int pop() { if (isEmpty()) { - throw new EmptyStackException(); + throw new EmptyStackException(); } else { - int value = top.val; - top = top.next; - return value; + int value = top.val; + top = top.next; + return value; } }