A039 - Exp - 5 Implementation of Doubly Linked List
A039 - Exp - 5 Implementation of Doubly Linked List
LAB Manual
PART A
(PART A : TO BE REFFERED BY STUDENTS)
Experiment No.05
A.1 Aim:
Implementation of doubly Linked List with following operations:
1. Creation
2. Insertion and
3. Deletion of the nodes
A.2 Prerequisite:
1. Knowledge of different operations performed on linked list data structure.
2. Knowledge of different types of linked list and their applications.
3. Fundamental concepts of C\C++.
A.3 Outcome:
After successful completion of this experiment students will be able to
A.4 Theory:
A.4.1. Introduction to Linked List
A.5 Procedure/Algorithm:
A.5.1:
Write OVERFLOW
Go to Step 7
Step 7: EXIT
Write OVERFLOW
Go to Step 11
[END OF IF]
[END OF LOOP]
Write OVERFLOW
Go to Step 11
[END OF IF]
[END OF LOOP]
Algorithm to delete the first node from the doubly linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 6
[END OF IF]
Step 6: EXIT
Write UNDERFLOW
Go to Step 7
[END OF IF]
[END OF LOOP]
Step 7: EXIT
Write UNDERFLOW
Go to Step 9
[END OF IF]
[END OF LOOP]
Step 9: EXIT
PART B
(PART B : TO BE COMPLETED BY STUDENTS)
(Students must submit the soft copy as per following segments within two hours of the
practical. The soft copy must be uploaded on the Blackboard or emailed to the
concerned lab in charge faculties at the end of the practical in case the there is no Black
board access available)
Code:
int data;
Node prev;
Node next;
Node(int value) {
data = value;
prev = null;
next = null;
}
}
public DoublyLinkedList() {
head = null;
tail = null;
if (head == null) {
head = newNode;
tail = newNode;
} else {
tail.next = newNode;
newNode.prev = tail;
tail = newNode;
if (head == null) {
head = newNode;
tail = newNode;
} else {
newNode.next = head;
head.prev = newNode;
head = newNode;
if (current.data == value) {
head = null;
tail = null;
head = current.next;
head.prev = null;
tail = current.prev;
tail.next = null;
} else {
current.prev.next = current.next;
current.next.prev = current.prev;
return;
current = current.next;
}
System.out.println("Node with value as '" + value + "' was not found :(");
current = current.next;
System.out.println();
boolean j = true;
int value;
int n;
while (j) {
System.out.println("5. Exit");
n = scanner.nextInt();
switch (n) {
case 1:
value = scanner.nextInt();
dll.append(value);
break;
case 2:
value = scanner.nextInt();
dll.prepend(value);
break;
case 3:
value = scanner.nextInt();
dll.deleteNode(value);
break;
case 4:
dll.display();
break;
case 5:
System.out.println("Exiting...");
j = false;
break;
default:
break;
}
scanner.close();
5. Exit
5. Exit
5. Exit
5. Exit
864
5. Exit
5. Exit
84
5. Exit
I have identified the need of appropriate selection of data structures, identified the steps of linked
list data structure selection and implemented different types of linked list data structures to solve
the problems in this practical. I have also learnt to differentiate between singly and doubly linked
lists.
B.4 Conclusion:
(Students must write the conclusion as per the attainment of individual outcome listed above and
learning/observation noted in section B.3)
The practical has been successfully performed, and I have obtained all necessary
outputs. In summary, the C++ code that is supplied implements a doubly linked list
with the fundamental operations of adding, removing, and moving nodes. The code
makes sure that nodes are linked correctly, deals with unusual deletion situations, and
accurately shows the list. It provides as a basic illustration of how to use doubly linked
lists in java code.
************************