Data Structures Question Set 4
Data Structures Question Set 4
Question 1
Write a C program to create a doubly linked list. Insert 7 elements into it, make sure one of the
entered elements is 24. Do the following operations on the singly linked list:
Traverse and display all the elements of the doubly linked list. When the traversing has
reached the end, display the linked list in reverse order i.e. traverse from the last
element to the first element using the PREV pointer of the linked list.
Insert the following element 19, 12, 25, 12 at the end of the linked list. Display the
elements of the resulting doubly linked list.
Remove 3 elements from the beginning of the linked list. Display the elements of the
resulting doubly linked list in reverse order.
Insert a new element 47 after the existing linked list element 24. If there are more than
one occurrence of 24, give user the choice where the new element must be inserted.
Display the elements of the resulting doubly linked list.
Insert a new element 55 before the existing linked list element 25. If there are more
than one occurrence of 25, give user the choice where the new element must be
inserted. Display the elements of the resulting doubly linked list in reverse order. Print
the size of the doubly linked list.
Insert 6 more elements into the doubly linked list. Display the elements of the resulting
linked list. Print the total number of elements in the doubly linked list.
Insert an element 194 after the 3rd element in the doubly linked list. Display the
elements of the resulting doubly linked list in reverse order. Print the total number of
elements in the linked list.
Question 2
Write a C program to create a doubly linked circular list. Insert 8 elements into it, make sure
one of the entered elements is 42. Do the following operations on the doubly linked circular
list:
Delete the last two element in the doubly linked circular list. Display the elements of the
resulting linked list. Print the total number of elements in the doubly linked circular list.
Delete the 3rd element in the doubly linked circular list. Display the elements of the
resulting linked list in reverse order. Print the total number of elements in the doubly
linked circular list.
Display the 3rd element in the linked list.
Insert the following elements 125, 63, 22, 62, 45, 18, 29 into the doubly linked circular
list after element 42. Display the elements of the resulting doubly linked circular list.
Delete one element before 62. If there are more than one occurrence of 62, give user
the choice where the element must be deleted from. Display the elements of the
resulting doubly linked circular list in reverse order. Print the total number of elements
in the doubly linked circular list.
Delete the first element of the doubly linked circular list. Display the elements of the
resulting doubly linked circular list in reverse order. Print the total number of doubly
linked circular list.
Read and insert two elements at the beginning of the doubly linked circular list. . Display
the elements of the resulting doubly linked circular list along with its size.
Delete one element after 22. If there are more than one occurrence of 22, give user the
choice where the element must be deleted from. Display the elements of the resulting
doubly linked circular list. Print the total number of elements in the doubly linked
circular list.
Delete two elements after 63. If there are more than one occurrence of 63, give user the
choice where the element must be deleted from. Display the elements of the resulting
doubly linked circular list. Print the total number of elements in the doubly linked
circular list.
Delete ‘n’ elements after 125. If there are more than one occurrence of 125, give user
the choice where the element must be deleted from. Display the elements of the
resulting doubly linked circular list in reverse order. Print the total number of elements
in the doubly linked circular list.
Question 3
Write a C program to read name and total marks of ‘n’ number of students in a batch. The
program must sort and store student names in alphabetical order. The program must also sort
and store a student list based on ascending order of marks.
You must use multi-linked lists with various links following ascendingly ordered and
alphabetically ordered records.
Question 4
Write a C program to read two doubly linked lists from the user. Make sure the elements of
both doubly linked lists are entered in ascending order. Now you have two doubly linked lists
each of which are sorted in ascending order. Do the following operation:
Merge the two doubly linked lists, the resulting linked must be in ascending order.
Question 5
Write a C program to create a circular doubly linked list and read 8 elements into them. Give
the following choices to the user:
Insert an element.
o Insert at the beginning.
o Insert at the end.
o Insert after a specific element. If there are more than one occurrence of that
element, consult the user for further instructions.
o Insert before a specific element. If there are more than one occurrence of that
element, consult the user for further instructions.
o Insert after a specific element. If there are more than one occurrence of that
element, consult the user for further instructions.
o Insert an element at a given position.
Insert more than one element before/after a specific element. If there are more than
one occurrence of that element, consult the user for further instructions.
Traversal
o Display the elements of the doubly linked list.
o Find the largest number/numbers in the doubly linked list.
o Find the smallest number/numbers in the doubly linked list.
o Find the third largest number/numbers in the doubly linked list.
o Find the second smallest number/numbers in the doubly linked list.
o Display the doubly linked list in reverse order.
Delete an element
o Delete at the beginning.
o Delete at the end.
o Delete after a specific element. If there are more than one occurrence of that
element, consult the user for further instructions.
o Delete before a specific element. If there are more than one occurrence of that
element, consult the user for further instructions.
o Delete an element at a given position.
Delete more than one element before/after a specific element.
Question 6
Write a C program to read two circular doubly linked lists from the user. Make sure the
elements of both linked lists are entered in descending order. Now you have two circular
doubly linked lists each of which are sorted in descending order. Do the following operation:
Merge the two circular doubly linked lists, the resulting linked list must be in descending
order.
Question 7
Write a C program to read to accept two doubly linked lists from the user, make sure some of
the elements are repeated in both the linked lists. Make a circular doubly linked list containing
those elements that are common in both the lists initially entered by the user.
Question 8
Write a C program to store the name, age, employee ID, salary, years of service, department of
all employees in a factory in random order. The departments can be any of the following:
Innovators
Designers
Engineering
Technical Division
Factory Workers
Transportation
Customer Service
Marketing
Do the following operations: