|
Definition
|
It's a linear data structure which stores data sequentially, but not in contiguous memory locations
|
|
Single Linked List
|
Each node has a pointer to the next node. Last node is always points to null
|
|
Double Linked List
|
Each node has 2 references :1 to previous node, the other to next node. Prev element of head is always null, next reference of tail node always points to null
|
|
Circular LinkedList
|
It could be a single or a double linkedlist. The difference is that instead of having the last node point to null, it points to head node. It is useful in implementing round-robin algorithms
|
Node newNode = new Node(data);
while(head.next != null){
head=head.next;
}
head.next = newNode;
Node newHead = new Node(data);
newHead.next = head;
head = newHead;
return head;
if(head == null) return;
if(head.next = null)
head = null;
else{
head.data = head.next.data;
head.next = head.next.next;
}
while(node.next.next!=null){
node = node.next;
}
node.next = null;
while(head.next !=null){
if(head.next.data == data){
head.next = head.next.next;
break;
}
head = head.next;
}
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.