0% found this document useful (0 votes)
30 views

DSA Lab Session 6

The document discusses a lab session on doubly linked lists. It covers creating an empty doubly linked list, inserting elements at the beginning, finding minimum and maximum elements, and counting the total elements. Operations like traversing forward and backward are also mentioned.

Uploaded by

beshahashenafe20
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

DSA Lab Session 6

The document discusses a lab session on doubly linked lists. It covers creating an empty doubly linked list, inserting elements at the beginning, finding minimum and maximum elements, and counting the total elements. Operations like traversing forward and backward are also mentioned.

Uploaded by

beshahashenafe20
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab session 6: Doubly Linked List

Objective

The objective of lab session 6 is


 To know the properties of doubly linked list
 To create an empty doubly linked list
 To write a full and block of C++ program for the given problem using doubly
linked list

Pre-lab Exercise

1. Which of the following is false about doubly linked list?


a. It is a type of a list, have two special pointers.
b. The last node carries a previous link as NULL to mark the end of the list.
c. It is possible to access the previous node.
2. Which of the following basic operation that doubly linked list support
a. Display forward − Displays the complete list in a forward manner.
b. Insert After − Adds an element after an item of the list.
c. Delete Last − Deletes an element from the end of the list.
d. Display backward − Displays the complete list in a backward manner.
e. Search − Searches an element using the given key.
3. Using the below diagram write the output of the following block of code

cout<<head->data<<endl;
cout<<tail->data<<endl;
head=head->next;
tail=tail->previous;
cout<<head->data<<endl;
cout<<tail->data<<endl;

1|Page
4. Create an empty doubly linked list having Employee structure name and the
following attribute: name, salary and age

In-lab Exercise (All exercises are in one file)

1. Creating an empty doubly linked list


Create an empty doubly linked list called Number containing a data
member.
2. Inserting an elements at the beginning in doubly linked list
Add the following elements at the beginning of the list in order, elements are:
45, 7, 12, 57, 90, 30, 84, 61
3. Showing the minimum and maximum items
Write two functions called maximum() and minimum() that return maximum
and minimum item value of a given list.
 To find the maximum /minimum item of the doubly linked list, you need
to compare each item of the list by allowing a max/min variable to
point to the first item of the list then starting to compare its data with its
next item. If the data of its next item is greater/less than the data of the
max/min, simply allow the max/min to catch the next item.
4. A program to count elements of doubly linked list
Write a simple C++ function that count elements of doubly linked list.
 To count all elements of the doubly linked list, we will need a loop to
traverse through the doubly linked list. We will let a pointer (i) of
ListElem type to point to the pfirst then move the pointer to its next
element and increase the number of item(t) one at a time by using a
while loop until the end of the doubly linked list is reached.

Post-lab Exercise

1. What are the advantages and disadvantages of a doubly linked list over a
singly linked list?
2. What three things does the node of a doubly linked list have to store?

2|Page

You might also like