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

DSA Assignment 03

DSA assignment 3 giki

Uploaded by

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

DSA Assignment 03

DSA assignment 3 giki

Uploaded by

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

1

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology


Faculty of Computer Science and Engineering
CS221/CE222- DSA (Fall 2024)
Assignment # 3
Instructor: Abdullah Bin Zarshaid.

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)

1. Display the Current Tasks (Traversal with Conditions):

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 prime numbers.

▪ 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.

2. Add a New Task (Conditional Insertion):

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.

3. Remove Completed Tasks Based on Task Priority (Custom LIFO):

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.

▪ Tasks that are at prime-numbered positions in the circular linked list.

▪ Personalized Instruction: Use the sum of the digits of your birthdate


(ddmmyy) to decide the number of tasks to pop, or all tasks that meet the
conditions, whichever is fewer.
4

4. Count Tasks Based on Dynamic Criteria:

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:

▪ Tasks that are divisible by 3.

▪ Tasks that contain a digit '7'.

▪ Tasks whose sum of digits is less than or equal to 15.

▪ Bonus: Count the tasks that have even-numbered indexes in the list.

5. Find a Task by ID Using Optimized Search:

o Implement a member function to search for a task by its ID using an optimized


search technique (binary search or jump search) instead of linear search. This will
require you to:

▪ Sort the tasks by their IDs.

▪ 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)

1. Traverse and View Events with Filters:

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 are multiples of 5.

▪ Event IDs that contain the same digit twice (e.g., 212, 377).

▪ If no events match the criteria, display "No events matching the filter."

2. Schedule an Event with Complex Criteria (Multi-Position Insertion):


5

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.

▪ If the event ID is a palindrome, insert it at the end of the queue.

▪ Personalized Instructions: Generate the event ID by taking the sum of the


ASCII values of the last three letters of your RegNo and adding the second
digit of your birth year.

▪ If no conditions are met, insert the event at the fourth position.

3. Dequeue Events by Custom Conditions (FIFO):

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 prime numbers.

▪ Event IDs that are less than the sum of the ASCII values of the letters in your
last name.

▪ Personalized Instruction: Dequeue the number of events based on the


number of vowels in your first name.

4. Search for an Event Using Dynamic Criteria:

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:

▪ Event ID is an odd number.

▪ Event ID is greater than a number provided by the user.

▪ Event ID contains a specific digit (e.g., 3).

▪ Personalized Instruction: Use the sum of the ASCII values of your full name
to determine the event ID to search for.

5. Reverse, Sort, and Merge Event Lists (Advanced Operations):

o Write a member function to perform the following sequence of operations:

▪ 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.

Grading Criteria for Each Question (45 Marks per Question)


Criteria Points Description
Correctness of Solution 15 Does the program perform all operations
correctly (insertion, deletion, traversal,
etc.)?
Object-Oriented Design 10 Are OOP concepts like classes, objects,
constructors, and destructors used
effectively?
Pointer Usage 05 Are pointers used effectively to manipulate
the linked list and perform operations?
Dynamic Memory 05 Are `new` and `delete` used correctly for
Management memory allocation and deallocation?
Modular Code with 05 Is the code modular with separate
Functions functions for each task?
Edge Case Handling 03 Does the code handle edge cases like
deleting from an empty list or inserting
into a full list?
Commenting and Code 02 Is the code well-commented and easy to
Readability understand?

Practice Challenges (Optional for Extra Credit)

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.

1. Advanced Circular Linked List Stack Challenges

1. Reverse Circular Linked List:

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.

2. Sort Stack by Task ID:


7

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.

3. Split Circular Linked List:

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.

4. Merge Two Circular Linked List Stacks:

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.

5. Delete Nodes by Condition:

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.

2. Advanced Doubly Linked List Queue Challenges

1. Add a Sub-List to a Node:

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.

2. Display Main and Sub-Lists:

o Write a function to display all events, including their respective sub-lists.

o Why: This provides a detailed view of all events and their related activities,
ensuring that no sub-event is missed.

3. Delete Alternate Nodes:


8

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.

4. Merge Two Doubly Linked Queues:

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.

5. Rotate Doubly Linked List:

o Implement a function to rotate the queue by n positions to the left or right,


depending on user input.

o Why: Rotating the queue can help reorganize events, such as changing the priority
or sequence of handling them.

You might also like