Merge pull request #1325 from mariaRoxana94/fix-error

Fixed 8XCorrectness_Bugs + 10XBad_Practice_Bugs + 14XDodgy_Code_Bugs
This commit is contained in:
Stepfen Shawn
2020-05-28 23:04:56 +08:00
committed by GitHub
25 changed files with 293 additions and 238 deletions

View File

@ -14,7 +14,7 @@ public class CircleLinkedList<E> {
//For better O.O design this should be private allows for better black box design
private int size;
//this will point to dummy node;
private Node<E> head;
private Node<E> head = null;
//constructer for class.. here we will make a dummy node for circly linked list implementation with reduced error catching as our list will never be empty;
public CircleLinkedList() {

View File

@ -86,9 +86,12 @@ public class DoublyLinkedList {
public Link 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)
if (head == null) {
tail = null;
} else {
head.previous = null; // oldHead --> 2ndElement(head) nothing pointing at old head so will be removed
}
return temp;
}
@ -100,10 +103,13 @@ public class DoublyLinkedList {
public Link deleteTail() {
Link temp = tail;
tail = tail.previous; // 2ndLast(tail) <--> oldTail --> null
tail.next = null; // 2ndLast(tail) --> null
if (tail == null) {
head = null;
} else{
tail.next = null; // 2ndLast(tail) --> null
}
return temp;
}