




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
data structure and algoritms lab
Typology: Papers
1 / 8
This page cannot be seen from the preview
Don't miss anything!
nd
General Tips
Overview: The goal of this lab is to learn how to implement basic functionalities in a Singly and Doubly linked list. You will be given a piece of code which is incomplete. Based on your learnings in the lecture classes and tutorials, try to complete the code and get the expected output. You should finish your task in the given lab timings.
The below search () method is a newly added feature to the GenericSinglyLinkedList implementation discussed in the class. The method basically searches whether there is a node in the list containing the given item. Complete the code highlighted as Task 1. Try to utilize the given isEqual() method to compare two elements of generic type. You should get the output as shown below: SNode
Output: Task 2: Newly added method swap () swaps the nodes containing the two given elements in the singly linked list. Again, you are given an incomplete code. You are free to refer to lecture slides to revise the concept of interchanging node pointers and the technique to swap two nodes. Do a thorough understanding of the code before you jump to coding. You should get the output as shown below: void SLinkedList
Output: Task 3: Add a new method reverse () which will reverse the nodes of the linked list. Note that the reversal of linked list should happen in-place i.e. using constant space complexity. Complete the code given below. Hints are given in as comments in the code. template
// Update the head pointer of the list } Output: Program 2 (DoublyLinkedList.cpp attached): Task 4: Add a new method isPalindrome() to the DoublyLinkedList class. The method will check if the list is a palindrome or not. A palindrome list is a type of linked list where the elements read the same forwards as they do backwards. Complete the code given below: bool DLinkedList::isPalindrome() { // Complete the initialization of begin and end pointers. // begin is the first node and end is the last node of the list. DNode *begin; DNode *end; while (begin != end) { // Check if the values of begin and end pointers are different. if (begin->next == end) break; //Update the begin and end pointers for the next iteration. }
Task 6 : Using pointer technique, find out if the doubly linked list has odd number of nodes or even number of nodes. Print “Odd” if number of nodes are odd, and “Even” otherwise. (hint: If the fast pointer reaches NULL, it is even, else if it reaches the last node then it is odd.)
Program 3 (Circular Linked List: CircularLL.cpp is given for your reference): Implement a scheduling algorithm which you will read in Operating Systems course later. Round Robin is a CPU scheduling algorithm where each process gets a fixed amount of time (time slice) to execute. If a process doesn't complete within its time slice, it's pre-empted and added to the end of the ready queue. This process repeats until all processes are completed. Implement this algorithm using a Circular linked list as discussed in the class. You may consider the below assumptions: Each process can be represented as a node in the circular linked list. The "next" pointer of each node points to the next process in the ready queue. The CPU scheduler can easily traverse the list in a circular fashion, giving each process its time slice. When a process completes or is pre-empted, it's simply removed from its current position and added to the end of the list. Take a set of processes with their CPU burst (time required with CPU) and a time slice (or time quantum) and produce an order of their completion as output. --------------------------