Name: ___________________ Registration Number: ______________
University of Management and Technology (UMT)
School of Systems and Technology (SST)
Department of Computer Science
Course: Data Structures and Algorithms (CC-2042)
Quiz Number 1
Date: November 18, 2024.
Semester: Fall-2024
Maximum Marks: 40
Time: 40 min
Instructor: Dr Bilal Ashfaq Ahmed
Advice to Student
1. Carefully read question and ensure you understand what is being asked
before starting your solution.
2. Include comments in your code to explain your logic and steps.
Objective: Write a modified version of the insert function in C++ for an ordered singly linked list
that:
1. Checks for Duplicates Before Insertion:
a. Before inserting a new item into the list, the function should check if the item
already exists in the list.
b. If the item is already present, the function should:
i. Output an error message indicating that the duplicate item was not
inserted.
ii. Not insert the duplicate item into the list.
2. Maintains the Order of the List:
a. The linked list should remain ordered in ascending order after the insertion (if the
item is inserted).
Function Requirements:
1. The function should handle insertion at any position in the list (beginning, middle, or
end).
2. Properly manage memory to prevent leaks (delete any dynamically allocated nodes if
necessary).
3. Use appropriate data structures and pointers for a singly linked list.
Best of Luck
1
University of Management and Technology (UMT)
School of Systems and Technology (SST)
Department of Computer Science
Course: Data Structures and Algorithms (CC-2042)
Quiz Number 1
Date: November 18, 2024.
Semester: Fall-2024
Maximum Marks: 40
Time: 40 min
Instructor: Dr Bilal Ashfaq Ahmed
Advice to Student
1. Carefully read question and ensure you understand what is being asked
before starting your solution.
2. Include comments in your code to explain your logic and steps.
Objective: Write a modified version of the insert function in C++ for an ordered singly linked list
that:
1. Checks for Duplicates Before Insertion:
a. Before inserting a new item into the list, the function should check if the item
already exists in the list.
b. If the item is already present, the function should:
i. Output an error message indicating that the duplicate item was not
inserted.
ii. Not insert the duplicate item into the list.
2. Maintains the Order of the List:
a. The linked list should remain ordered in ascending order after the insertion (if the
item is inserted).
Function Requirements:
1. The function should handle insertion at any position in the list (beginning, middle, or
end).
2. Properly manage memory to prevent leaks (delete any dynamically allocated nodes if
necessary).
3. Use appropriate data structures and pointers for a singly linked list.
Best of Luck
1