-
-
Notifications
You must be signed in to change notification settings - Fork 5
New Beginner and Advanced Practice and Solutions #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
03c3ff7
added HelloWorld Example and Solution!
armeetj 2a48437
Added Comments exercise to practice comments (Java Beginners, Chapter 1)
armeetj bb68ef0
finished VariableTypes exercise and solution
armeetj a2a2eb8
fixed VariableTypes package names
armeetj b9f1238
ApplesOranges exercise complete
armeetj 3c4a093
finished CarDealership exercise
armeetj f1858cb
completed LinkedList implementation Challenge for Advanced Group
armeetj cfc050c
fix package name errors for Solutions
armeetj db58c32
formatted
armeetj 542423b
attempt #2: fixing formatting
armeetj 85bda2c
adding to comments
armeetj e92fb41
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj f6977c7
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj cca23c2
Update src/com/codefortomorrow/beginner/chapter2/practice/VariableTyp…
armeetj 47b6725
Update src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOran…
armeetj 199fb87
Update src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOran…
armeetj 40b8662
Update src/com/codefortomorrow/beginner/chapter2/solutions/VariableTy…
armeetj 1b3fbfd
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj 6610010
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj 84ad074
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj 640cb85
Update src/com/codefortomorrow/advanced/chapter16/practice/LinkedList…
armeetj 8017009
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj e4e6db9
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj 9ac5b2d
made requested changes
armeetj 2b5e02d
Merge branch 'master' of https://github.com/ArmeetJatyani/java
armeetj 2d8da5d
made all changes 2
armeetj 17cb81d
Update src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.…
armeetj acd3db8
Update src/com/codefortomorrow/beginner/chapter2/practice/ApplesOrang…
armeetj 0995938
Update src/com/codefortomorrow/beginner/chapter2/practice/ApplesOrang…
armeetj 508db44
Update/add javadoc comments (for consistency)
phrdang 44713c4
revision 3
armeetj 9413324
Merge branch 'master' of https://github.com/ArmeetJatyani/java
armeetj 48dc66b
Update src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld…
armeetj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
completed LinkedList implementation Challenge for Advanced Group
- Loading branch information
commit f1858cbec7a53a3d9c1040eba0925a21e3db0a03
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.codefortomorrow.advanced.chapter16.practice; | ||
|
|
||
| /** | ||
| * @author ArmeetJatyani | ||
| * March 2021 | ||
| * | ||
| * Implement a simple LinkedList | ||
| * You will need to create a LinkedListNode class, which represents each item/node in the linked list | ||
| * Required functionality... | ||
| * - head(): get head of list | ||
| * - tail(): get tail of list | ||
| * - add(): add to tail of list | ||
| * - push(): push to head of list | ||
| * - pop(): remove head of list | ||
| * - toString(): return a String representation of the list | ||
| */ | ||
|
|
||
| public class LinkedList { | ||
| public static void main(String[] args) { | ||
| // write your code here | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| class LinkedListNode | ||
159 changes: 159 additions & 0 deletions
159
src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| package com.codefortomorrow.advanced.chapter16.solutions; | ||
|
|
||
| // using Lombok for Getters and Setters | ||
| import lombok.Setter; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
armeetj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // UUID to represent each node's unique ID | ||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * @author ArmeetJatyani | ||
| * March 2021 | ||
| * | ||
| * Implement a simple LinkedList | ||
| * You will need to create a LinkedListNode class, which represents each item/node in the linked list | ||
| * Required functionality... | ||
| * - head(): get head of list | ||
| * - tail(): get tail of list | ||
| * - add(): add to tail of list | ||
| * - push(): push to head of list | ||
| * - pop(): remove head of list | ||
| * - toString(): return a String representation of the list | ||
| */ | ||
|
|
||
| @Setter | ||
| public class LinkedList { | ||
| private LinkedListNode head; | ||
|
|
||
| /** | ||
armeetj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * default constructor | ||
| */ | ||
| public LinkedList() { | ||
| head = null; | ||
| } | ||
|
|
||
| /** | ||
| * constructor with first value | ||
| * @param value | ||
| */ | ||
| public LinkedList(int value) { | ||
| // create first node | ||
| head = new LinkedListNode(value, null); | ||
| } | ||
|
|
||
| /** | ||
| * get head of Linked List | ||
| * @return | ||
| */ | ||
| public LinkedListNode head() { | ||
| return this.head; | ||
| } | ||
|
|
||
| /** | ||
| * traverse and get tail of linked list | ||
| * @return | ||
| */ | ||
| public LinkedListNode tail() { | ||
| LinkedListNode current = head; | ||
| if(current == null) return null; | ||
|
|
||
| while (current.getNext() != null) { | ||
| current = current.getNext(); | ||
armeetj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return current; | ||
| } | ||
|
|
||
| /** | ||
| * add new element (node) to linked list | ||
| * @param value | ||
| */ | ||
| public void add(int value) { | ||
| LinkedListNode tail = tail(); | ||
| if (tail == null) { | ||
| head = new LinkedListNode(value, null); | ||
| return; | ||
armeetj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
armeetj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| tail.setNext(new LinkedListNode(value, null)); | ||
armeetj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * push (add to head of linkedlist) | ||
| * @return | ||
| */ | ||
| public void push(int value) { | ||
| LinkedListNode newHead = new LinkedListNode(value, head); | ||
| head = newHead; | ||
| } | ||
|
|
||
| /** | ||
| * pop (remove head of linkedlist) | ||
| * @return | ||
| */ | ||
| public LinkedListNode pop() { | ||
| LinkedListNode popped = head; | ||
| head = head.getNext(); | ||
armeetj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return popped; | ||
| } | ||
|
|
||
| /** | ||
| * to String | ||
| * @return | ||
| */ | ||
| @Override | ||
| public String toString() { | ||
| String list = "["; | ||
| LinkedListNode current = head; | ||
| if(current == null) return null; | ||
| do { | ||
| list += Integer.toString(current.getValue()) + ", "; | ||
armeetj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| current = current.getNext(); | ||
| } | ||
| while (current != null); | ||
|
|
||
| list = list.substring(0, list.length() - 2); | ||
armeetj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return list + "]"; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @Getter | ||
| @Setter | ||
| class Node | ||
| { | ||
| private UUID ID; | ||
| private int value; | ||
|
|
||
| public Node(int value) | ||
| { | ||
| this.ID = UUID.randomUUID(); | ||
phrdang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.value = value; | ||
| } | ||
|
|
||
| public int value() | ||
| { | ||
| return this.value; | ||
| } | ||
| } | ||
|
|
||
| @Getter | ||
| @Setter | ||
| class LinkedListNode extends Node | ||
| { | ||
| private LinkedListNode next; | ||
|
|
||
| public LinkedListNode(int value, LinkedListNode next) | ||
| { | ||
| super(value); | ||
| this.next = next; | ||
| } | ||
|
|
||
| public LinkedListNode next() | ||
| { | ||
| return this.next; | ||
| } | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.