From eb01780ae61066dc2b86094464eab2daf0584f8b Mon Sep 17 00:00:00 2001 From: Doru Kesriyeli Date: Sun, 7 Oct 2018 16:55:52 -0700 Subject: [PATCH 1/4] fixed spelling mistakes --- DataStructures/Lists/SinglyLinkedList.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DataStructures/Lists/SinglyLinkedList.java b/DataStructures/Lists/SinglyLinkedList.java index 32747cf2830f..d7d721b2ec1c 100644 --- a/DataStructures/Lists/SinglyLinkedList.java +++ b/DataStructures/Lists/SinglyLinkedList.java @@ -2,10 +2,10 @@ * This class implements a SinglyLinked List. This is done * using SinglyLinkedList class and a LinkForLinkedList Class. * - * A linked list is implar to an array, it hold values. + * A linked list is similar to an array, it hold values. * However, links in a linked list do not have indexes. With * a linked list you do not need to predetermine it's size as - * it gorws and shrinks as it is edited. This is an example of + * it grows and shrinks as it is edited. This is an example of * a singly linked list. Elements can only be added/removed * at the head/front of the list. * @@ -120,7 +120,7 @@ public static void main(String args[]){ /** * This class is the nodes of the SinglyLinked List. - * They consist of a vlue and a pointer to the node + * They consist of a value and a pointer to the node * after them. * * @author Unknown From ae2029424b99a997c584b388be96c30b7d5a765a Mon Sep 17 00:00:00 2001 From: Doru Kesriyeli Date: Sun, 7 Oct 2018 17:20:32 -0700 Subject: [PATCH 2/4] removed unused return values --- DataStructures/Lists/DoublyLinkedList.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/DataStructures/Lists/DoublyLinkedList.java b/DataStructures/Lists/DoublyLinkedList.java index c3229d9c336d..1d15e495b53b 100644 --- a/DataStructures/Lists/DoublyLinkedList.java +++ b/DataStructures/Lists/DoublyLinkedList.java @@ -60,13 +60,12 @@ public void insertTail(int x){ * * @return The new head */ - public Link deleteHead(){ + public void deleteHead(){ Link temp = head; head = head.next; // oldHead <--> 2ndElement(head) head.previous = null; // oldHead --> 2ndElement(head) nothing pointing at old head so will be removed if(head == null) tail = null; - return temp; } /** @@ -74,11 +73,11 @@ public Link deleteHead(){ * * @return The new tail */ - public Link deleteTail(){ + public void deleteTail(){ Link temp = tail; tail = tail.previous; // 2ndLast(tail) <--> oldTail --> null tail.next = null; // 2ndLast(tail) --> null - return temp; + } /** @@ -87,7 +86,7 @@ public Link deleteTail(){ * @param x element to be deleted * @return Link deleted */ - public Link delete(int x){ + public void delete(int x){ Link current = head; while(current.value != x) //Find the position to delete @@ -102,8 +101,7 @@ else if(current == tail) else{ //Before: 1 <--> 2(current) <--> 3 current.previous.next = current.next; // 1 --> 3 current.next.previous = current.previous; // 1 <--> 3 - } - return current; + } } /** @@ -211,4 +209,4 @@ public static void main(String args[]){ myList.insertOrdered(3); myList.display(); // <-- 3(head) <--> 10 <--> 13 <--> 23 <--> 67(tail) --> } -} \ No newline at end of file +} From 3562e8398510390703afc27b7457cf5eb07aba66 Mon Sep 17 00:00:00 2001 From: Doru Kesriyeli Date: Sun, 7 Oct 2018 17:28:50 -0700 Subject: [PATCH 3/4] added constructor --- DataStructures/Lists/DoublyLinkedList.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/DataStructures/Lists/DoublyLinkedList.java b/DataStructures/Lists/DoublyLinkedList.java index 1d15e495b53b..d236fe68e9e5 100644 --- a/DataStructures/Lists/DoublyLinkedList.java +++ b/DataStructures/Lists/DoublyLinkedList.java @@ -20,12 +20,24 @@ class DoublyLinkedList{ private Link tail; /** - * Constructor + * Default Constructor */ public DoublyLinkedList(){ head = null; tail = null; } + + /** + * Constructs a list containing the elements of the array + * @param array the array whose elements are to be placed into this list + * @throws NullPointerException if the specified collection is null + */ + public DoublyLinkedList(int[] array){ + if (array == null) throw new NullPointerException(); + for (int i:array) { + insertTail(i); + } + } /** * Insert an element at the head From cc0980c23d2e400caf16d5878068ff4cbcff048c Mon Sep 17 00:00:00 2001 From: Doru Kesriyeli Date: Sun, 7 Oct 2018 17:29:23 -0700 Subject: [PATCH 4/4] Update DoublyLinkedList.java --- DataStructures/Lists/DoublyLinkedList.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DataStructures/Lists/DoublyLinkedList.java b/DataStructures/Lists/DoublyLinkedList.java index d236fe68e9e5..27c1a1a24580 100644 --- a/DataStructures/Lists/DoublyLinkedList.java +++ b/DataStructures/Lists/DoublyLinkedList.java @@ -34,9 +34,9 @@ public DoublyLinkedList(){ */ public DoublyLinkedList(int[] array){ if (array == null) throw new NullPointerException(); - for (int i:array) { - insertTail(i); - } + for (int i:array) { + insertTail(i); + } } /**