DSA Assignment 03
DSA Assignment 03
Total Marks: 90
Circular and Doubly Linked List Operations Using Stacks and Queues in C++ (OOP
Concepts Only)
Objective:
This assignment aims to deepen your understanding of linked lists in C++, focusing on key
operations involving circular and doubly linked lists, while using stacks and queues to manage and
manipulate data. You will implement these linked list operations using object-oriented
programming (OOP) principles in C++. This assignment will enhance your understanding of OOP
concepts such as classes, objects, constructors, destructors, and encapsulation. The assignment is
personalized based on your Registration Number (RegNo), Name, and Birthdate to ensure a unique
experience for each student.
Some concepts in this assignment may be new to you, and it is encouraged that you search and
learn from different sources (books, online resources, or programming forums). However, copying
without understanding will not help you succeed in the post-assignment quiz and subsequent
evaluations.
Instructions:
• Write all solutions by hand on paper and submit the written assignment. Digital submissions
are not allowed.
• You are required to use C++ object-oriented programming concepts, including classes, objects,
constructors, destructors, and appropriate access specifiers for all parts of the assignment.
• No built-in functions are allowed (e.g., sort, find, etc.). You must manually write the logic for all
linked list operations such as insertion, deletion, and traversal.
• Ensure proper dynamic memory management by using `new` and `delete` to allocate and
deallocate memory.
• Your inputs (node data, task IDs, etc.) will be generated based on your RegNo, Name, and
Birthdate, as detailed in each question. Each student will have different values based on their
unique details.
• Code Commenting: Every function and major block of your code should be well-commented.
Explain your logic in a clear and concise manner.
• Checkpoint Submissions: Submit the assignment in two parts: Part 1 (Question 1) and Part 2
(Question 2). For each part, include a brief explanation of your approach.
2
• Post-Assignment Quiz: After submission, you will be required to pass a quiz based on your
implementation. The quiz will assess your understanding of the concepts used in your code.
Important Note:
After submitting your assignment, you will have a quiz announced by your instructor. The marks
you score in the quiz will determine the final marks for your assignment. If you complete the
assignment correctly but without understanding, your quiz performance will reflect this and impact
your assignment score accordingly.
3
Assignment Tasks:
Question 1: Circular Linked List Stack Management System (Stack Implementation Using
Circular Linked List)
o Write a member function to traverse and display all task IDs in the circular linked
list stack. However, tasks should only be displayed if they meet the following
conditions:
▪ Task IDs that are divisible by the sum of digits of your RegNo.
▪ If the list contains no such tasks, display the message "No tasks matching the
criteria."
o Hint: You will need to implement a prime number check and modulus operation
logic.
o Create a member function to insert a new task ID into the circular linked list stack.
However, this time, the task should be inserted based on the following rules:
▪ If the sum of the digits of the task ID is even, the task should be inserted at
the top of the stack.
▪ If the sum of the digits is odd, the task should be inserted at the second
position in the stack.
▪ Use your RegNo as the task ID. If your RegNo is 2023007, the task ID will be
2023007.
o Modify the stack to support task removal (deletion) based on both LIFO (Last In,
First Out) and task priority. The tasks should be popped based on:
▪ Task IDs greater than the ASCII sum of the first two letters of your birth
month.
o Write a member function to count tasks based on a dynamic user input. The user
should input one of the following conditions, and the program should count only the
tasks that match the given condition:
▪ Bonus: Count the tasks that have even-numbered indexes in the list.
▪ Personalized Instruction: Use the sum of the ASCII values of your full name
to generate the task ID to search for.
▪ Bonus: After finding the task, reverse the stack to maintain its LIFO
property.
Question 2: Doubly Linked List Event Management System (Queue Implementation Using
Doubly Linked List)
o Write a member function to traverse the doubly linked list in both directions
(forward and backward) and display only the events that meet the following
criteria:
▪ Event IDs that contain the same digit twice (e.g., 212, 377).
▪ If no events match the criteria, display "No events matching the filter."
o Create a member function to insert a new event ID in the doubly linked list queue
based on the following logic:
▪ If the event ID is divisible by 4, insert the event at the third position in the
list.
o Create a member function to remove events from the front of the queue, but remove
only the events that satisfy the following:
▪ Event IDs that are less than the sum of the ASCII values of the letters in your
last name.
o Implement a member function to search for an event by its ID, but the search
criteria should be dynamic, based on user input. The user should choose one of the
following conditions:
▪ Personalized Instruction: Use the sum of the ASCII values of your full name
to determine the event ID to search for.
▪ Reverse the doubly linked list (swap the next and prev pointers for each
node).
▪ Sort the event list by event ID in ascending order after reversing it.
6
▪ Merge the current event list with another doubly linked list provided by the
user, maintaining correct forward and backward pointers.
▪ Bonus: After merging, remove duplicate event IDs and display the unique
events.
The following challenges are designed for students who want to go beyond the basic assignment to
better understand linked list complexities and earn extra credit (2 Marks in Quiz no#3). These tasks
are not mandatory but are encouraged for those interested in gaining a deeper understanding of
the material.
o Write a member function to reverse the entire stack (circular linked list). This will
require careful manipulation to maintain the circular nature of the linked list.
o Why: Reversing the stack can help reorganize the order of tasks, especially when
the latest task needs to be processed first.
o Write a member function that sorts the stack based on the task ID in ascending
order, keeping the circular property intact.
o Why: Sorting allows prioritization of tasks, making sure the most important ones
are on top.
o Create a function to split the circular linked list stack into two halves. If there are an
odd number of nodes, the extra node should go to the first half.
o Why: Splitting the stack is useful when dividing tasks between two teams or
managing workload efficiently.
o Write a function to merge two circular linked list stacks into one and maintain the
circular property.
o Why: Merging stacks helps in combining tasks from different sources to form a
unified workflow.
o Implement a function to delete all nodes where the task ID is even. This should
update the stack properly, maintaining its circular structure.
o Why: Deleting nodes based on a condition allows for filtering out unnecessary tasks
from the stack.
o Write a member function that allows each event node to have a sub-list (another
doubly linked list). Each event in the queue can contain a reference to a list of 'sub-
events' associated with that main event.
o Why: Adding sub-lists allows a single event to contain multiple sub-events, which is
helpful for events with sessions or dependencies.
o Why: This provides a detailed view of all events and their related activities,
ensuring that no sub-event is missed.
o Write a function to delete every alternate node from the doubly linked list.
o Why: Deleting alternate nodes can be helpful in situations where you need to reduce
the number of events quickly or perform load balancing.
o Write a function to merge two doubly linked list queues into one, ensuring that the
nodes are connected correctly in both forward and reverse directions.
o Why: Merging queues is useful when integrating two sets of events into a single
timeline for streamlined processing.
o Why: Rotating the queue can help reorganize events, such as changing the priority
or sequence of handling them.