Skip to content

fixed spelling mistakes #556

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

Merged
merged 4 commits into from
Oct 8, 2018
Merged
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
28 changes: 19 additions & 9 deletions DataStructures/Lists/DoublyLinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,25 +72,24 @@ 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;
}

/**
* Delete the element at the tail
*
* @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;

}

/**
Expand All @@ -87,7 +98,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
Expand All @@ -102,8 +113,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;
}
}

/**
Expand Down Expand Up @@ -211,4 +221,4 @@ public static void main(String args[]){
myList.insertOrdered(3);
myList.display(); // <-- 3(head) <--> 10 <--> 13 <--> 23 <--> 67(tail) -->
}
}
}
6 changes: 3 additions & 3 deletions DataStructures/Lists/SinglyLinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down