1. The document provides a list of 25 operations to implement for a singly linked list data structure in Python, including adding and removing nodes from different positions, searching, sorting, and other common list operations.
2. Students are asked to select some of the operations to implement for singly linked lists of integers, and also implement singly linked lists of strings and doubly linked and circular linked lists of integers.
3. Implementing more of the listed operations will better prepare students for their final practical and written exams.
1. The document provides a list of 25 operations to implement for a singly linked list data structure in Python, including adding and removing nodes from different positions, searching, sorting, and other common list operations.
2. Students are asked to select some of the operations to implement for singly linked lists of integers, and also implement singly linked lists of strings and doubly linked and circular linked lists of integers.
3. Implementing more of the listed operations will better prepare students for their final practical and written exams.
1. The document provides a list of 25 operations to implement for a singly linked list data structure in Python, including adding and removing nodes from different positions, searching, sorting, and other common list operations.
2. Students are asked to select some of the operations to implement for singly linked lists of integers, and also implement singly linked lists of strings and doubly linked and circular linked lists of integers.
3. Implementing more of the listed operations will better prepare students for their final practical and written exams.
1. The document provides a list of 25 operations to implement for a singly linked list data structure in Python, including adding and removing nodes from different positions, searching, sorting, and other common list operations.
2. Students are asked to select some of the operations to implement for singly linked lists of integers, and also implement singly linked lists of strings and doubly linked and circular linked lists of integers.
3. Implementing more of the listed operations will better prepare students for their final practical and written exams.
Download as DOC, PDF, TXT or read online from Scribd
Download as doc, pdf, or txt
You are on page 1/ 2
Lab 1-List Data Structures
Practical exercises
Note: You can select and do some options according to your ability only. We would like to note you that the more questions you do the better for you in doing final practical and writing exams.
Question 1. Write a program in Python to implement a singly linked list of integer
values with the following operations : 1. def addToHead(x) - add a node with value x at the head of a list. 2. def addToTail(x) - add a node with value x at the tail of a list. 3. def addAfter(p, x) - add a node with value x after the node p. 4. def traverse() - traverse from head to tail and dislay info of all nodes in the list. 5. def deleteFromHead() - delete the head and return its info. 6. def deleteFromTail() - delete the tail and return its info. 7. def deleteAter(p) - delete the node after the node p and return its info. 8. def del(x) - delele the first node whose info is equal to x. 9. def search(x) - search and return the reference to the first node having info x. 10. def count() - count and return number of nodes in the list. 11. def del(i) - delete an i-th node on the list. Besure that such a node exists. 12. def sort() - sort the list by ascending order of info. 13. def del(p) - delete node p if it exists in the list. 14. def toArray() - create and return array containing info of all nodes in the list. 15. Merge two ordered singly linked lists of integers into one ordered list. 16. def addBefore(p, x) - add a node with value x before the node p. 17. Attach a singly linked list to the end of another singly linked list. 18. def max() - find and return the maximum value in the list. 19. def min() - find and return the minimum value in the list. 20. def sum() - return the sum of all values in the list. 21. def avg() - return the average of all values in the list. 22. def sorted() - check and return true if the list is sorted, return false if the list is not sorted. 23. def insert(x) - insert node with value x into sorted list so that the new list is sorted. 24. Reverse a singly linked list using only one pass through the list. 25. Check whether two singly linked list have the same contents. Question 2. Write a program in Python to implement a singly linked list of string values with 1 - 10 operations in the above list. Question 3. Write a program in Python to implement a doubly linked list of integer values with the above operations. Question 4. Write a program in Python to implement a circular linked list of integer values with the above operations.