-
Notifications
You must be signed in to change notification settings - Fork 0
LinkedList + tests #1
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
Open
vhalubkova
wants to merge
1
commit into
main
Choose a base branch
from
forCheck
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
There are no files selected for viewing
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,38 @@ | ||
| target/ | ||
| !.mvn/wrapper/maven-wrapper.jar | ||
| !**/src/main/**/target/ | ||
| !**/src/test/**/target/ | ||
|
|
||
| ### IntelliJ IDEA ### | ||
| .idea/modules.xml | ||
| .idea/jarRepositories.xml | ||
| .idea/compiler.xml | ||
| .idea/libraries/ | ||
| *.iws | ||
| *.iml | ||
| *.ipr | ||
|
|
||
| ### Eclipse ### | ||
| .apt_generated | ||
| .classpath | ||
| .factorypath | ||
| .project | ||
| .settings | ||
| .springBeans | ||
| .sts4-cache | ||
|
|
||
| ### NetBeans ### | ||
| /nbproject/private/ | ||
| /nbbuild/ | ||
| /dist/ | ||
| /nbdist/ | ||
| /.nb-gradle/ | ||
| build/ | ||
| !**/src/main/**/build/ | ||
| !**/src/test/**/build/ | ||
|
|
||
| ### VS Code ### | ||
| .vscode/ | ||
|
|
||
| ### Mac OS ### | ||
| .DS_Store |
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,95 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>org.example</groupId> | ||
| <artifactId>taskCore1</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
|
|
||
| <properties> | ||
| <maven.compiler.source>21</maven.compiler.source> | ||
| <maven.compiler.target>21</maven.compiler.target> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-engine</artifactId> | ||
| <version>5.8.1</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.platform</groupId> | ||
| <artifactId>junit-platform-surefire-provider</artifactId> | ||
| <version>1.3.2</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>4.12</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-api</artifactId> | ||
| <version>5.8.2</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-params</artifactId> | ||
| <version>5.8.2</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.example</groupId> | ||
| <artifactId>hippodrome</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-params</artifactId> | ||
| <version>5.8.2</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-junit-jupiter</artifactId> | ||
| <version>4.2.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-inline</artifactId> | ||
| <version>4.2.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-core</artifactId> | ||
| <version>4.2.0</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <version>2.19.1</version> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.junit.platform</groupId> | ||
| <artifactId>junit-platform-surefire-provider</artifactId> | ||
| <version>1.3.2</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> | ||
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,32 @@ | ||
| package org.example; | ||
|
|
||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| MyLinkedList list = new MyLinkedList(); | ||
| list.add(0,"aaa"); | ||
| list.add(1,"eee"); | ||
| list.add(2,"bbb"); | ||
| list.add(3,"rrr"); | ||
| //list.printAll(); | ||
|
|
||
| //list.addFirst("yyy"); | ||
| //list.addLast("qqq"); | ||
| //list.printAll(); | ||
|
|
||
|
|
||
| // System.out.println(list.getFirst().getValue()); | ||
| // System.out.println(list.getLast().getValue()); | ||
| System.out.println(list.get(1).getValue()); | ||
|
|
||
| // list.removeFirst(); | ||
| // list.printAll(); | ||
|
|
||
| // list.removeLast(); | ||
| // list.printAll(); | ||
|
|
||
| // list.remove(2); | ||
| // list.printAll(); | ||
|
|
||
| } | ||
| } |
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,136 @@ | ||
| package org.example; | ||
|
|
||
| public class MyLinkedList<T> { | ||
|
|
||
| private Node first = new Node(); | ||
| private Node last = new Node(); | ||
|
|
||
|
|
||
| public MyLinkedList() { | ||
| first.next = last; | ||
| last.prev = first; | ||
| } | ||
|
|
||
| public void printAll() { | ||
| Node current = first.next; | ||
| while ((current != null) && (current != last)) { | ||
| System.out.println(current.value); | ||
| current = current.next; | ||
| } | ||
| } | ||
|
|
||
| // size() - returns the size of the list | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not use comments. turn it into javaDock |
||
| public int size() { | ||
| Node current = first.next; | ||
| int count = 0; | ||
| while ((current != null) && (current != last)) { | ||
| count++; | ||
| current = current.next; | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| // addFirst(el) - adds the element in the beginning of the list | ||
| public void addFirst(T value) { | ||
| Node current = new Node(); | ||
| current.value = value; | ||
| current.prev = first; | ||
| current.next = first.next; | ||
| first.next = current; | ||
| } | ||
|
|
||
| // addLast(el) - adds the element in the end of the list | ||
| public void addLast(T value) { | ||
| Node current = new Node(); | ||
| current.value = value; | ||
| current.prev = last.prev; | ||
| current.next = last; | ||
| last.prev.next = current; | ||
| last.prev = current; | ||
| } | ||
|
|
||
| // add(index, el) - adds the element in the list by index | ||
| public void add(int index, T value) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's better return somthing. |
||
| Node current = new Node(); | ||
| current.value = value; | ||
| Node previous = first; | ||
| if (index == 0) { | ||
| current.prev = first; | ||
| current.next = last; | ||
|
|
||
| first.next = current; | ||
| last.prev = current; | ||
| } else { | ||
| for (int i = 0; i < index; i++) { | ||
| previous = previous.next; | ||
| if (previous == last) { | ||
| throw new StringIndexOutOfBoundsException("Index out of bounds"); | ||
| } | ||
| } | ||
| current.prev = previous; | ||
| current.next = previous.next; | ||
| previous.next.prev = current; | ||
| previous.next = current; | ||
| } | ||
| } | ||
|
|
||
| // getFirst() - returns the first element of the list | ||
| public Node getFirst() { | ||
| return first.next; | ||
| } | ||
|
|
||
| // getLast() - returns the last element of the list | ||
| public Node getLast() { | ||
| return last.prev; | ||
| } | ||
|
|
||
| // get(index) - returns the element by index | ||
| public Node get(int index) { | ||
| Node previous = first; | ||
| for (int i = 0; i < index; i++) { | ||
| if (previous == last.prev) { | ||
| throw new NullPointerException("Index out of bounds"); | ||
| } | ||
| previous = previous.next; | ||
| } | ||
| return previous.next; | ||
| } | ||
|
|
||
| // removeFirst() - retrieve and remove the first element of the list | ||
| public void removeFirst() { | ||
| first.next = first.next.next; | ||
| first.next.prev = first; | ||
| } | ||
|
|
||
| // removeLast() - retrieve and remove the last element of the list | ||
| public void removeLast() { | ||
| last.prev = last.prev.prev; | ||
| last.prev.next = last; | ||
| } | ||
|
|
||
| // remove(index) - retrieve and remove the element of the list by index | ||
| public void remove(int index) { | ||
| Node previous = first; | ||
| for (int i = 0; i < index; i++) { | ||
| if (previous == last.prev) { | ||
| throw new NullPointerException("Index out of bounds"); | ||
| } | ||
| previous = previous.next; | ||
| } | ||
| previous.next = previous.next.next; | ||
| previous.next.prev = previous; | ||
| } | ||
|
|
||
|
|
||
| public static class Node<T> { | ||
| private Node prev; | ||
| private T value; | ||
| private Node next; | ||
|
|
||
| public T getValue() { | ||
| return value; | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write versions in properties