Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Collections2/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Collections2/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Collections2/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Collections2/Collections2.iml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_17">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
Expand Down
4 changes: 4 additions & 0 deletions Collections2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
<version>5.7.1</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>
14 changes: 7 additions & 7 deletions Collections2/src/main/java/itis/homework/impl/MyArrayList.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package itis.homework.impl;

import java.util.List;

public class MyArrayList<T> implements List<T> {

}
//package itis.homework.impl;
//
//import java.util.List;
//
//public class MyArrayList<T> implements List<T> {
//
//}
160 changes: 159 additions & 1 deletion Collections2/src/main/java/itis/homework/impl/MyLinkedList.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,165 @@
package itis.homework.impl;

import java.util.List;
import java.util.*;

public class MyLinkedList<T> implements List<T> {

private static class Node {
Object value;
Node previous;
Node next;

public Node(Object value) {
this.value = value;
this.previous = null;
this.next = null;
}

@Override
public boolean equals(Object o) {
return value.equals(o);
}
}

Node head;
Node tail;
int size = 0;


public int size() {
return size;
}

public boolean add(T t) {
if (head == null) {
head = new Node(t);
tail = head;
} else {
tail.next = new Node(t);
tail.next.previous = tail;
tail = tail.next;
}
size++;
return true;
}

public boolean remove(Object o) {
if (isEmpty()) {
throw new NoSuchElementException();
}
if (size == 1) {
clear();
return true;
}
Node current = head;
while (!current.equals(o)) {
if(current.next == null) {
throw new NoSuchElementException();
}
current = current.next;
}
if (current.value == null) {
throw new NoSuchElementException();
}
Node pre = current.previous;
Node next = current.next;

if (pre == null) {
head = next;
head.previous = null;
} else if(next == null) {
tail = pre;
tail.next = null;
} else {
pre.next = next;
next.previous = pre;
}
size--;
return true;
}

public boolean isEmpty() {
if (this.head == null) {
return true;
} else return false;
}

public T get(int index) {
Node current = head;
for (int i = 0; i < index; i++) {
current = current.next;
}
return (T) current.value;
}
public void clear() {
size = 0;
}

public boolean contains(Object o) {
return false;
}

public Iterator<T> iterator() {
return null;
}

public Object[] toArray() {
return new Object[0];
}

public <T1> T1[] toArray(T1[] a) {
return null;
}

public boolean containsAll(Collection<?> c) {
return false;
}

public boolean addAll(Collection<? extends T> c) {
return false;
}

public boolean addAll(int index, Collection<? extends T> c) {
return false;
}

public boolean removeAll(Collection<?> c) {
return false;
}

public boolean retainAll(Collection<?> c) {
return false;
}

public void add(int index, T element) {

}

public T remove(int index) {
return null;
}

public T set(int index, T element) {
return null;
}

public int indexOf(Object o) {
return 0;
}

public int lastIndexOf(Object o) {
return 0;
}

public ListIterator<T> listIterator() {
return null;
}

public ListIterator<T> listIterator(int index) {
return null;
}

public List<T> subList(int fromIndex, int toIndex) {
return null;
}
}
6 changes: 3 additions & 3 deletions Collections2/src/test/java/HomeWorkCheck.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import itis.homework.impl.MyArrayList;
import itis.homework.impl.MyLinkedList;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -13,7 +13,7 @@ static void setup() {

@Test
void check() {
List<String> list = new MyArrayList<String>();
List<String> list = new MyLinkedList<String>();
list.add("One");
list.add("Two");
list.add("Three");
Expand All @@ -31,7 +31,7 @@ void check() {
list.add("Fifteen");

Assertions.assertEquals(list.get(2), "Three");
list.remove(2);
list.remove("Three");
Assertions.assertEquals(list.get(2), "Four");
}
}