DSL5
DSL5
class LinkedList {
Node head;
class Node {
int data;
Node next;
Node(int d)
{
data = d;
next = null;
}
}
llist.push(5);
llist.push(3);
llist.push(10);
llist.push(7);
llist.push(19);
System.out.println(
"\nLinked List after Deletion of 10:");
llist.printList();
}
}
3.
i) Create and define a Node class which represents the nodes in the list.
ii) Define another class for creating the circular linked list
Diagram of Circularly linked list
Head
5 3 10 7 19
5.
class main
{
static class circular
{
int data;
Node next;
};
head.next = start;
return start;
}
newNode.data = data;
newNode.next = (head);
(head) = newNode;
return head;
}
rotate(head);
6. In a Doubly Linked we can traverse in both directions since each node has the address
of its previous and the next node.
iii) DLL nodes contains 3 fields known as data field, a previous link field and a
next link field.
7. I) find(Eben)
Step 1: IF HEAD == NULL
Step 2: Set pointer = HEAD
Step 3: Set i = 0
Step 4: Repeat step 5 to 7 while pointer != NULL
Step 5: IF pointer → data = F
Step 6: i = i + 1
Step 7: pointer = pointer → next
Step 8: Exit