Vous êtes sur la page 1sur 3

Laboratory Assignments on Linked List

1. Write a program to insert elements in a singly linked list in sorted order by the node values. 2. Write a program to implement a circular linked list. Use it to realize a left shift register and display the list content after shifting operation. 3. Write a program to reverse a linear list (by construction). Display the content of the reversed list. 4. Create two linked lists of arbitrary size m and n number of nodes respectively. Display the elements in the two lists with elements locally sorted by their position in increasing order. For example, if two lists are as follows: List1: 10->20>40->30->NULL and List2: 5->25->35->NULL; The display function will print 5, 10, 20, 25, 35, 40, 30. 5. Create a list to store information of a set of processes where each process consists of following members/elements: <Process id, arrival time, execution time, next ptr>. For example, process P0 with arrival time 1 ms and execution time of 10 ms will be represented by the list node P0->1->10->NULL. (a) Write a program to create a list of such n processes. (b) Write a function to display the processes in their order of arrival to the system. (c) Consider the above definition of list of processes. A non-preemptive scheduler schedules processes for execution based on shortest execution time of the processes. If there is a tie between two processes in terms of their execution time, then the tie is broken by their arrival time (i.e., the process arrives first will be scheduled first in case of a tie in execution time). The scheduling decision making process will be applied at every time unit and only the arrived processes in the list at that time will be considered for scheduling process. Write a function to realize such scheduler on an arbitrary list of processes. Display the processes as per their scheduling order. 6. During execution of a program, OS needs to reference various memory slots (called pages) to bring them from disk to main memory. However, the size of page frame in the main memory is usually less than the number of pages required to bring in to for execution of the complete program. So, during execution of the program, pages are replaced from the page frame to create space for new pages. A Least recently used (LRU) page replacement policy works by replacing least recently referenced page in the frame. For example, consider the following page reference sequence: <1, 2, 1, 3, 4, 5, 1, 2, 1>, where, the number indicates the page IDs. Consider, the page frame is a linked list to accommodate 3 pages. Now, if LRU page replacement policy is used, the content of the list (page frame) will be as follows:

1->NULL, 1->2->NULL, 1->2->NULL, 1->2->3->NULL, 1->4->3->NULL (page 4 replaces page 2 because it is least recently used page compared to page 1 and page 3 present in the frame), 5->4->3->NULL, 5->4->1->NULL, 5->2->1->NULL, 5->2->1->NULL. Write a program to realize a page frame of size 3, and then to insert elements in it corresponding to a input page sequence of length 15 (page sequence will be given by the user). Once the list is full, the insertion will follow LRU policy as described above. If the element to be inserted is already present in the list, then it is not required to insert that element in the list. Display the content of page frame list at the end of program execution (or after final page reference). 7. Consider a Tabular list representation, where there exists an array of 10 list node pointers. Each element in the array is a pointer to a list. The nodes to be inserted in the tabular list according to the following function: List index of node with value, node->val = (node->val) mod 10 For example, consider the nodes with values 17, 11, 13, 47, 68, 66, 70, 92, 102, 333, 566 are to be inserted in the tabular list. Then, the list structure after insertion will be as follows: 0 1 2 3 4 5 6 7 8 9 70 11 92 13 NULL NULL 66 17 NULL NULL NULL NULL 102 333 NULL NULL 566 47

NULL NULL

NULL NULL

(17 mod 10 = 7; therefore node with 7 value will be inserted in the 7 th index list, similarly 11 will be inserted with 1st index list, 47 will be inserted as 2nd element in the 7th element list) Write a program to implement tabular list representation. Insert n number of elements in the list. Display the content of all 10 lists after the final insertion. 8. Write a program to implement 1-level indexed sequential search using two linked lists (data list and index list). 9. Create a doubly linked list of n nodes. Use insert node function to insert each node in the list (start with an empty list). The insertion of node must contain following four options: (i) insert at beginning (ii) insert at end (iii) insert at kth position from beginning (iv) insert at kth position from end.

10. Write a program to delete nodes from a doubly linked list. The deletion of node must contain following three options: (i) delete from the end (iii) delete at kth position from beginning (iv) delete at kth position from end. 11. Write a program to implement a queue using doubly linked list (Hint: Insertion in the queue will occur from head end and deletion will occur from last end) 12. Write a program to reverse a doubly linked list.

Vous aimerez peut-être aussi