From c0bc709c61eb5b9fe80973a5b8c4d8908035fcc5 Mon Sep 17 00:00:00 2001 From: Richa Kiran <64418209+richk21@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:46:27 +0530 Subject: [PATCH 01/11] Create CircularDoublyLinkedListTest.java added tests for CircularDoublyLinkedListTest --- .../lists/CircularDoublyLinkedListTest.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java diff --git a/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java new file mode 100644 index 000000000000..447af88e2577 --- /dev/null +++ b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java @@ -0,0 +1,83 @@ +package com.thealgorithms.datastructures.lists; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class CircularDoublyLinkedListTest { + + private CircularDoublyLinkedList list; + + @BeforeEach + public void setUp() { + list = new CircularDoublyLinkedList<>(); + } + + @Test + public void testInitialSize() { + assertEquals(0, list.getSize(), "Initial size should be 0."); + } + + @Test + public void testAppendAndSize() { + list.append(10); + list.append(20); + list.append(30); + + assertEquals(3, list.getSize(), "Size after appends should be 3."); + assertEquals("[ 10, 20, 30 ]", list.toString(), "List content should match appended values."); + } + + @Test + public void testRemove() { + list.append(10); + list.append(20); + list.append(30); + + int removed = list.remove(1); + assertEquals(20, removed, "Removed element at index 1 should be 20."); + + assertEquals("[ 10, 30 ]", list.toString(), "List content should reflect removal."); + assertEquals(2, list.getSize(), "Size after removal should be 2."); + + removed = list.remove(0); + assertEquals(10, removed, "Removed element at index 0 should be 10."); + assertEquals("[ 30 ]", list.toString(), "List content should reflect second removal."); + assertEquals(1, list.getSize(), "Size after second removal should be 1."); + } + + @Test + public void testRemoveInvalidIndex() { + list.append(10); + list.append(20); + + assertThrows(IndexOutOfBoundsException.class, () -> list.remove(2), + "Removing at invalid index 2 should throw exception."); + assertThrows(IndexOutOfBoundsException.class, () -> list.remove(-1), + "Removing at negative index should throw exception."); + } + + @Test + public void testToStringEmpty() { + assertEquals("[]", list.toString(), "Empty list should display as []."); + } + + @Test + public void testSingleElement() { + list.append(10); + + assertEquals(1, list.getSize(), "Size after adding single element should be 1."); + assertEquals("[ 10 ]", list.toString(), "Single element list string should be formatted correctly."); + int removed = list.remove(0); + assertEquals(10, removed, "Removed element should be the one appended."); + assertEquals("[]", list.toString(), "List should be empty after removing last element."); + assertEquals(0, list.getSize(), "Size after removing last element should be 0."); + } + + @Test + public void testNullAppend() { + assertThrows(NullPointerException.class, () -> list.append(null), + "Appending null should throw NullPointerException."); + } +} From a4a46cd4e9b5ab544aa108a03c790cb02586bffe Mon Sep 17 00:00:00 2001 From: Richa Kiran <64418209+richk21@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:53:54 +0530 Subject: [PATCH 02/11] Create CircularDoublyLinkedList.java added circular doubly linked list code --- .../CircularDoublyLinkedList.java | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 src/main/java/com/thealgorithms/CircularDoublyLinkedList.java diff --git a/src/main/java/com/thealgorithms/CircularDoublyLinkedList.java b/src/main/java/com/thealgorithms/CircularDoublyLinkedList.java new file mode 100644 index 000000000000..02a32e3d9915 --- /dev/null +++ b/src/main/java/com/thealgorithms/CircularDoublyLinkedList.java @@ -0,0 +1,160 @@ +package com.thealgorithms.datastructures.lists; + +/** + * This class is a circular doubly linked list implementation. In a circular + * doubly linked list, + * the last node points back to the first node and the first node points back to + * the last node, + * creating a circular chain in both directions. + * + * This implementation includes basic operations such as appending elements to + * the end, + * removing elements from a specified position, and converting the list to a + * string representation. + * + * @param the type of elements held in this list + */ +public class CircularDoublyLinkedList { + static final class Node { + Node next; + Node prev; + E value; + + private Node(E value, Node next, Node prev) { + this.value = value; + this.next = next; + this.prev = prev; + } + } + + private int size; + Node head = null; + + /** + * Initializes a new circular doubly linked list. A dummy head node is used for + * simplicity, + * pointing initially to itself to ensure the list is never empty. + */ + public CircularDoublyLinkedList() { + head = new Node<>(null, null, null); + head.next = head; + head.prev = head; + size = 0; + } + + /** + * Returns the current size of the list. + * + * @return the number of elements in the list + */ + public int getSize() { + return size; + } + + /** + * Appends a new element to the end of the list. Throws a NullPointerException + * if + * a null value is provided. + * + * @param value the value to append to the list + * @throws NullPointerException if the value is null + */ + public void append(E value) { + if (value == null) { + throw new NullPointerException("Cannot add null element to the list"); + } + Node newNode = new Node<>(value, head, head.prev); + head.prev.next = newNode; + head.prev = newNode; + size++; + } + + /** + * Returns a string representation of the list in the format "[ element1, + * element2, ... ]". + * An empty list is represented as "[]". + * + * @return the string representation of the list + */ + public String toString() { + if (size == 0) { + return "[]"; + } + StringBuilder sb = new StringBuilder("[ "); + Node current = head.next; + while (current != head) { + sb.append(current.value); + if (current.next != head) { + sb.append(", "); + } + current = current.next; + } + sb.append(" ]"); + return sb.toString(); + } + + /** + * Removes and returns the element at the specified position in the list. + * Throws an IndexOutOfBoundsException if the position is invalid. + * + * @param pos the position of the element to remove + * @return the value of the removed element - pop operation + * @throws IndexOutOfBoundsException if the position is out of range + */ + public E remove(int pos) { + if (pos >= size || pos < 0) { + throw new IndexOutOfBoundsException("Position out of bounds"); + } + Node current = head.next; + for (int i = 0; i < pos; i++) { + current = current.next; + } + current.prev.next = current.next; + current.next.prev = current.prev; + E removedValue = current.value; + current = null; + size--; + return removedValue; + } + + /** + * A small demonstration of the above implemented circular doubly linked list + * here we're initializing the circular doubly linked list, chronologically + * adding and removing the linked list elements and demonstrating methods like + * getSize() + */ + public static void main(String[] args) { + CircularDoublyLinkedList list = new CircularDoublyLinkedList<>(); + + System.out.println("Initial list: " + list); + System.out.println("Initial size: " + list.getSize()); + + System.out.println("Appending 10, 20, 30."); + list.append(10); + list.append(20); + list.append(30); + + System.out.println("List content: " + list); + System.out.println("List size: " + list.getSize()); + + System.out.println("Removing element at position 1."); + int removed = list.remove(1); + System.out.println("Removed element: " + removed); + + System.out.println("List content after removal: " + list); + System.out.println("List size after removal: " + list.getSize()); + + System.out.println("Removing element at position 0."); + removed = list.remove(0); + System.out.println("Removed element: " + removed); + + System.out.println("List content after second removal: " + list); + System.out.println("List size after second removal: " + list.getSize()); + + System.out.println("Appending 40."); + list.append(40); + + System.out.println("List content: " + list); + System.out.println("List size: " + list.getSize()); + } +} From 33887ed19fb28f758ee1978c9e50b6ee4b744fb1 Mon Sep 17 00:00:00 2001 From: Richa Kiran <64418209+richk21@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:22:48 +0530 Subject: [PATCH 03/11] Rename src/main/java/com/thealgorithms/CircularDoublyLinkedList.java to src/main/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedList.java --- .../{ => datastructures/lists}/CircularDoublyLinkedList.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/java/com/thealgorithms/{ => datastructures/lists}/CircularDoublyLinkedList.java (100%) diff --git a/src/main/java/com/thealgorithms/CircularDoublyLinkedList.java b/src/main/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedList.java similarity index 100% rename from src/main/java/com/thealgorithms/CircularDoublyLinkedList.java rename to src/main/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedList.java From 44425511168d951b5415a6d4c870f9dfd9b1202b Mon Sep 17 00:00:00 2001 From: Richa Kiran <64418209+richk21@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:27:48 +0530 Subject: [PATCH 04/11] Update CircularDoublyLinkedListTest.java fixed build issues --- .../datastructures/lists/CircularDoublyLinkedListTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java index 447af88e2577..1b67f5555851 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java @@ -1,6 +1,7 @@ package com.thealgorithms.datastructures.lists; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; From ec44bf19c9f844886a2c0de384d9eed176514f02 Mon Sep 17 00:00:00 2001 From: Richa Kiran <64418209+richk21@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:30:19 +0530 Subject: [PATCH 05/11] Update CircularDoublyLinkedListTest.java fixed lint issues --- .../datastructures/lists/CircularDoublyLinkedListTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java index 1b67f5555851..5ecf13b17cf7 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java @@ -53,10 +53,8 @@ public void testRemoveInvalidIndex() { list.append(10); list.append(20); - assertThrows(IndexOutOfBoundsException.class, () -> list.remove(2), - "Removing at invalid index 2 should throw exception."); - assertThrows(IndexOutOfBoundsException.class, () -> list.remove(-1), - "Removing at negative index should throw exception."); + assertThrows(IndexOutOfBoundsException.class, () -> list.remove(2), "Removing at invalid index 2 should throw exception."); + assertThrows(IndexOutOfBoundsException.class, () -> list.remove(-1), "Removing at negative index should throw exception."); } @Test From 10ed5276780e81cc5e325a378c6593148415f222 Mon Sep 17 00:00:00 2001 From: Richa Kiran <64418209+richk21@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:37:57 +0530 Subject: [PATCH 06/11] Update CircularDoublyLinkedListTest.java lint issue fix --- .../datastructures/lists/CircularDoublyLinkedListTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java index 5ecf13b17cf7..eb8ca1d37a98 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java @@ -76,7 +76,6 @@ public void testSingleElement() { @Test public void testNullAppend() { - assertThrows(NullPointerException.class, () -> list.append(null), - "Appending null should throw NullPointerException."); + assertThrows(NullPointerException.class, () -> list.append(null), "Appending null should throw NullPointerException."); } } From adcecd4437039c5b43a32f6bdca351f3faf571b4 Mon Sep 17 00:00:00 2001 From: richa Date: Wed, 1 Oct 2025 07:22:58 +0000 Subject: [PATCH 07/11] added more tests for circular doubly linked list --- .../lists/CircularDoublyLinkedListTest.java | 205 +++++++++++------- 1 file changed, 124 insertions(+), 81 deletions(-) diff --git a/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java index eb8ca1d37a98..12f842ab6261 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java @@ -1,81 +1,124 @@ -package com.thealgorithms.datastructures.lists; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class CircularDoublyLinkedListTest { - - private CircularDoublyLinkedList list; - - @BeforeEach - public void setUp() { - list = new CircularDoublyLinkedList<>(); - } - - @Test - public void testInitialSize() { - assertEquals(0, list.getSize(), "Initial size should be 0."); - } - - @Test - public void testAppendAndSize() { - list.append(10); - list.append(20); - list.append(30); - - assertEquals(3, list.getSize(), "Size after appends should be 3."); - assertEquals("[ 10, 20, 30 ]", list.toString(), "List content should match appended values."); - } - - @Test - public void testRemove() { - list.append(10); - list.append(20); - list.append(30); - - int removed = list.remove(1); - assertEquals(20, removed, "Removed element at index 1 should be 20."); - - assertEquals("[ 10, 30 ]", list.toString(), "List content should reflect removal."); - assertEquals(2, list.getSize(), "Size after removal should be 2."); - - removed = list.remove(0); - assertEquals(10, removed, "Removed element at index 0 should be 10."); - assertEquals("[ 30 ]", list.toString(), "List content should reflect second removal."); - assertEquals(1, list.getSize(), "Size after second removal should be 1."); - } - - @Test - public void testRemoveInvalidIndex() { - list.append(10); - list.append(20); - - assertThrows(IndexOutOfBoundsException.class, () -> list.remove(2), "Removing at invalid index 2 should throw exception."); - assertThrows(IndexOutOfBoundsException.class, () -> list.remove(-1), "Removing at negative index should throw exception."); - } - - @Test - public void testToStringEmpty() { - assertEquals("[]", list.toString(), "Empty list should display as []."); - } - - @Test - public void testSingleElement() { - list.append(10); - - assertEquals(1, list.getSize(), "Size after adding single element should be 1."); - assertEquals("[ 10 ]", list.toString(), "Single element list string should be formatted correctly."); - int removed = list.remove(0); - assertEquals(10, removed, "Removed element should be the one appended."); - assertEquals("[]", list.toString(), "List should be empty after removing last element."); - assertEquals(0, list.getSize(), "Size after removing last element should be 0."); - } - - @Test - public void testNullAppend() { - assertThrows(NullPointerException.class, () -> list.append(null), "Appending null should throw NullPointerException."); - } -} +package com.thealgorithms.datastructures.lists; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class CircularDoublyLinkedListTest { + + private CircularDoublyLinkedList list; + + @BeforeEach + public void setUp() { + list = new CircularDoublyLinkedList<>(); + } + + @Test + public void testInitialSize() { + assertEquals(0, list.getSize(), "Initial size should be 0."); + } + + @Test + public void testAppendAndSize() { + list.append(10); + list.append(20); + list.append(30); + + assertEquals(3, list.getSize(), "Size after appends should be 3."); + assertEquals("[ 10, 20, 30 ]", list.toString(), "List content should match appended values."); + } + + @Test + public void testRemove() { + list.append(10); + list.append(20); + list.append(30); + + int removed = list.remove(1); + assertEquals(20, removed, "Removed element at index 1 should be 20."); + + assertEquals("[ 10, 30 ]", list.toString(), "List content should reflect removal."); + assertEquals(2, list.getSize(), "Size after removal should be 2."); + + removed = list.remove(0); + assertEquals(10, removed, "Removed element at index 0 should be 10."); + assertEquals("[ 30 ]", list.toString(), "List content should reflect second removal."); + assertEquals(1, list.getSize(), "Size after second removal should be 1."); + } + + @Test + public void testRemoveInvalidIndex() { + list.append(10); + list.append(20); + + assertThrows(IndexOutOfBoundsException.class, () -> list.remove(2), + "Removing at invalid index 2 should throw exception."); + assertThrows(IndexOutOfBoundsException.class, () -> list.remove(-1), + "Removing at negative index should throw exception."); + } + + @Test + public void testToStringEmpty() { + assertEquals("[]", list.toString(), "Empty list should display as []."); + } + + @Test + public void testSingleElement() { + list.append(10); + + assertEquals(1, list.getSize(), "Size after adding single element should be 1."); + assertEquals("[ 10 ]", list.toString(), "Single element list string should be formatted correctly."); + int removed = list.remove(0); + assertEquals(10, removed, "Removed element should be the one appended."); + assertEquals("[]", list.toString(), "List should be empty after removing last element."); + assertEquals(0, list.getSize(), "Size after removing last element should be 0."); + } + + @Test + public void testNullAppend() { + assertThrows(NullPointerException.class, () -> list.append(null), + "Appending null should throw NullPointerException."); + } + + @Test + public void testRemoveLastPosition() { + list.append(10); + list.append(20); + list.append(30); + int removed = list.remove(list.getSize() - 1); + assertEquals(30, removed, "Last element removed should be 30."); + assertEquals(2, list.getSize(), "Size should decrease after removing last element."); + } + + @Test + public void testRemoveFromEmptyThrows() { + assertThrows(IndexOutOfBoundsException.class, () -> list.remove(0), "Remove from empty list should throw."); + } + + @Test + public void testRepeatedAppendAndRemove() { + for (int i = 0; i < 100; i++) { + list.append(i); + } + assertEquals(100, list.getSize()); + + for (int i = 99; i >= 0; i--) { + int removed = list.remove(i); + assertEquals(i, removed, "Removed element should match appended value."); + } + assertEquals(0, list.getSize(), "List should be empty after all removes."); + } + + @Test + public void testToStringAfterMultipleRemoves() { + list.append(1); + list.append(2); + list.append(3); + list.remove(2); + list.remove(0); + assertEquals("[ 2 ]", list.toString(), "ToString should correctly represent remaining elements."); + } + +} From de5e2fbfed1d8f11f002eb3ce57b1a6986472a4c Mon Sep 17 00:00:00 2001 From: Richa Kiran <64418209+richk21@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:55:38 +0530 Subject: [PATCH 08/11] Update CircularDoublyLinkedListTest.java lint issue fix --- .../lists/CircularDoublyLinkedListTest.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java index 12f842ab6261..910cfa37ec58 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java @@ -53,10 +53,8 @@ public void testRemoveInvalidIndex() { list.append(10); list.append(20); - assertThrows(IndexOutOfBoundsException.class, () -> list.remove(2), - "Removing at invalid index 2 should throw exception."); - assertThrows(IndexOutOfBoundsException.class, () -> list.remove(-1), - "Removing at negative index should throw exception."); + assertThrows(IndexOutOfBoundsException.class, () -> list.remove(2), "Removing at invalid index 2 should throw exception."); + assertThrows(IndexOutOfBoundsException.class, () -> list.remove(-1), "Removing at negative index should throw exception."); } @Test @@ -78,8 +76,7 @@ public void testSingleElement() { @Test public void testNullAppend() { - assertThrows(NullPointerException.class, () -> list.append(null), - "Appending null should throw NullPointerException."); + assertThrows(NullPointerException.class, () -> list.append(null), "Appending null should throw NullPointerException."); } @Test @@ -122,3 +119,4 @@ public void testToStringAfterMultipleRemoves() { } } + From c9ab40041c33339466e969dd92654e5b757cc038 Mon Sep 17 00:00:00 2001 From: Richa Kiran <64418209+richk21@users.noreply.github.com> Date: Wed, 1 Oct 2025 13:01:34 +0530 Subject: [PATCH 09/11] Update CircularDoublyLinkedListTest.java removed extra spaces --- .../datastructures/lists/CircularDoublyLinkedListTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java index 910cfa37ec58..faa2765a3264 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedListTest.java @@ -117,6 +117,4 @@ public void testToStringAfterMultipleRemoves() { list.remove(0); assertEquals("[ 2 ]", list.toString(), "ToString should correctly represent remaining elements."); } - } - From 9dd2f5484814da10051473a67a3d05515d246820 Mon Sep 17 00:00:00 2001 From: Richa Kiran <64418209+richk21@users.noreply.github.com> Date: Wed, 1 Oct 2025 13:20:53 +0530 Subject: [PATCH 10/11] Update CircularDoublyLinkedList.java removed unnecessary null assignment --- .../datastructures/lists/CircularDoublyLinkedList.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedList.java b/src/main/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedList.java index 02a32e3d9915..8b277cd39f9d 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedList.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedList.java @@ -112,7 +112,6 @@ public E remove(int pos) { current.prev.next = current.next; current.next.prev = current.prev; E removedValue = current.value; - current = null; size--; return removedValue; } From 9eacb594e2de76f786e573286340a2ad167ff656 Mon Sep 17 00:00:00 2001 From: Richa Kiran <64418209+richk21@users.noreply.github.com> Date: Wed, 1 Oct 2025 13:30:29 +0530 Subject: [PATCH 11/11] Update CircularDoublyLinkedList.java removed main method --- .../lists/CircularDoublyLinkedList.java | 41 ------------------- 1 file changed, 41 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedList.java b/src/main/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedList.java index 8b277cd39f9d..fbb48854c449 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedList.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/CircularDoublyLinkedList.java @@ -115,45 +115,4 @@ public E remove(int pos) { size--; return removedValue; } - - /** - * A small demonstration of the above implemented circular doubly linked list - * here we're initializing the circular doubly linked list, chronologically - * adding and removing the linked list elements and demonstrating methods like - * getSize() - */ - public static void main(String[] args) { - CircularDoublyLinkedList list = new CircularDoublyLinkedList<>(); - - System.out.println("Initial list: " + list); - System.out.println("Initial size: " + list.getSize()); - - System.out.println("Appending 10, 20, 30."); - list.append(10); - list.append(20); - list.append(30); - - System.out.println("List content: " + list); - System.out.println("List size: " + list.getSize()); - - System.out.println("Removing element at position 1."); - int removed = list.remove(1); - System.out.println("Removed element: " + removed); - - System.out.println("List content after removal: " + list); - System.out.println("List size after removal: " + list.getSize()); - - System.out.println("Removing element at position 0."); - removed = list.remove(0); - System.out.println("Removed element: " + removed); - - System.out.println("List content after second removal: " + list); - System.out.println("List size after second removal: " + list.getSize()); - - System.out.println("Appending 40."); - list.append(40); - - System.out.println("List content: " + list); - System.out.println("List size: " + list.getSize()); - } }