Assignment-1 Theory
Assignment-1 Theory
Islamabad Campus
Department of Computer Science
Must be hand written due date:23-10-24 5:30PM
Theory Assignment-1
CLO-1: SO(1,2):Employ linear data structures to solve computing problems.
What to do:
Implement the given tasks in C++ language.
Diagrammatically show the impact of each important step.
1. Print the singly linked list in reverse order by iteration (without using any additional
array/List/linked list etc.).
2. Print the singly linked list in reverse order by recursion (without using any additional
array/List/linked list etc.).
3. Reverse the linked list (before and after the operation, address of each node will
remain same).
4. Remove duplicates from a linked list.
5. Detect loop or cycle in a linked list.
6. Swap any two nodes (only links will change, not to swap the values, so after swap
addresses of nodes will remain same).
7. Assume that you have a linked list having even and odd values. Your task is to spit the
list into two separate lists of even and odd without changing their addresses. Also there
should be a single method to print all linked list means you just have to pass the
address of first node and it should print the list accordingly.
8. Swap any two nodes with their addresses (after swap there will be no change of address).
9. Reverse the first half and second of the linked list i.e. assume that the list is:
1->2->3->4->5->6->7->8
After calling the reverse method the list should be:
4->3->2->1->8->7->6->5
10. Given a singly linked list, write a function to swap elements pairwise i.e. assume that the
list is:
Input : 1->2->3->4->5->6->NULL
Output : 2->1->4->3->6->5->NULL
2. Suppose you are working on a project to develop an inventory management system for a
retail chain that has multiple stores in different cities across the country. The system
should be able to maintain the records of the items in each store. Each store has different
sections, and each section has different products. To implement this system, use best
suitable Data Structure to maintain the records of items, locations, stores, and sections.
Write the methods to perform following operations:
Add a new section in a store (toys, grocery, fruits….)
Store an item in a particular section of a particular store.
Remove an item in a particular section of a particular store.
Display the list of all items of a particular section of a store.
Display the list of items for a given store.
For example, to store an item in a location in a particular store, you can search for
the node that represents the store, then search for the node that represents the
section in the store, and then search for the node that represents the location in the
section. Then, you can add a new node to the linked list that represents the items
stored in the location. Same procedure will be for deletion operation.