Skip to content

Commit

Permalink
Merge branch 'master' into task1
Browse files Browse the repository at this point in the history
  • Loading branch information
Javohir004 committed Apr 24, 2024
2 parents ad920c6 + e98625b commit 8e8fa15
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 29 deletions.
124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

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

Binary file not shown.
Binary file not shown.
Binary file modified out/production/B30_Javohir_Sharifjonov_2/Main.class
Binary file not shown.
100 changes: 100 additions & 0 deletions src/CustomLinkedList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import java.util.Objects;
public class CustomLinkedList<E>{
private Node head;
private Node last;
private int size;

private class Node {
E value;
Node next;
Node prev;

public Node(E value, Node next, Node prev) {
this.value = value;
this.next = next;
this.prev = prev;
}

public Node(E value) {
this.value = value;
}
}


public void add(E element) {
if (Objects.isNull(head)) {
head = new Node(element);
last = head;
size++;
return;
}

last.next = new Node(element);
last.next.prev = last;
last = last.next;

size++;
}


/** Bo'lganicha bajardimda **/
public void remove(E element){
Node current = head;
if(current.value.equals(element)){
head = current.next;
return;
}

while (current != null) {
if (current.value.equals(element)) {
current.prev.next = current.next;
size--;
return;
}
if( current.next == null){
current.next.prev = null;
last = current.prev;
return;
}
current = current.next;
}
}



/**DIQQAT !!! bu yerda aynan nechinchi index daligiga qaraganman demoqchimanki 0 chi index yo'q deb olganman
* va sanashni 1 chi indexdan boshlaganman.
*/
public E get(int index){
--index;
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException("Index " + index + " is out of bounds for length " + size);
}
Node next = head.next;

if(index == 0){
return head.value;
}

for (int i = 1; i < index; i++) {
next = next.next;
}

return next.value;
}

public boolean contains(E element){
Node current = head;
while(current != null){
if(current.value.equals(element)){
return true;
}
current = current.next;
}
return false;
}


}


12 changes: 10 additions & 2 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@

public class Main {
public static void main(String[] args) {

System.out.println("Hello world !!!");
CustomLinkedList<Integer> test = new CustomLinkedList<>();
test.add(1);
test.add(2);
test.add(3);
test.add(8);
test.add(5);
System.out.println(test.get(2));
test.remove(1);
System.out.println(test.get(1));
}
}
27 changes: 0 additions & 27 deletions src/Text.txt

This file was deleted.

0 comments on commit 8e8fa15

Please sign in to comment.