Question 5.1 Write a Python program that creates an unordered, singly-linked list consisting of 8 items. Each item in the linked list should be a number. You can use the code given in the lecture...


Question 5.1<br>Write a Python program that creates an unordered, singly-linked list consisting of 8 items. Each item<br>in the linked list should be a number. You can use the code given in the lecture slides for your Node<br>and UnorderedList classes.<br>Your node class should contain the following functions:<br>• a constructor<br>• get_data() – returns the data in the node<br>• get_next() – returns the next node in the list<br>set_data() – sets the data in the node to the value given as a parameter<br>set_next() – sets the node that this node links to, to the node given as a parameter<br>Your UnorderedList class should contain the following functions:<br>• a constructor<br>• add() – adds a node to the head of the list, containing the number given in the parameter<br>• is_empty() – returns True if the list is empty, and False otherwise<br>• size() – returns the size of the list<br>• print_list() – displays the contents of all nodes in the list<br>Add code to create an UnorderedList object, and call its add() function to add 8 items to the list. Call<br>the is_empty(), size() and print_list() functions to show that they work. In your logbook, show your<br>code and the output when you run the code.<br>The 8 numbers you will add them to the list should be your student ID.<br>Example output:<br>Creating a linked list containing the following numbers: 21, 35, 40, 50, 15, 8<br>Displaying the contents of the list using the print_list () function<br>O 15 50 40 35 21<br>Testing the is_empty() function<br>False<br>Testing the size () function<br>Question 5.2<br>Add a function called search() to your UnorderedList class in Question 5.1. This function should take<br>a number as a parameter and return True if the number is contained in the linked list, or False if the<br>number is not in the list.<br>Add code to your program to allow the user to enter a number, and search for the number in your<br>linked list. Display a message to the user indicating if the number they entered was found in the list<br>or not. In your logbook, include your code, and also output that shows you have tested the search<br>function for a number in the list and a number not in the list.<br>Example output:<br>Please enter a number to search for in the list: 50<br>True<br>Please enter a number to search for in the list: 28<br>False<br>

Extracted text: Question 5.1 Write a Python program that creates an unordered, singly-linked list consisting of 8 items. Each item in the linked list should be a number. You can use the code given in the lecture slides for your Node and UnorderedList classes. Your node class should contain the following functions: • a constructor • get_data() – returns the data in the node • get_next() – returns the next node in the list set_data() – sets the data in the node to the value given as a parameter set_next() – sets the node that this node links to, to the node given as a parameter Your UnorderedList class should contain the following functions: • a constructor • add() – adds a node to the head of the list, containing the number given in the parameter • is_empty() – returns True if the list is empty, and False otherwise • size() – returns the size of the list • print_list() – displays the contents of all nodes in the list Add code to create an UnorderedList object, and call its add() function to add 8 items to the list. Call the is_empty(), size() and print_list() functions to show that they work. In your logbook, show your code and the output when you run the code. The 8 numbers you will add them to the list should be your student ID. Example output: Creating a linked list containing the following numbers: 21, 35, 40, 50, 15, 8 Displaying the contents of the list using the print_list () function O 15 50 40 35 21 Testing the is_empty() function False Testing the size () function Question 5.2 Add a function called search() to your UnorderedList class in Question 5.1. This function should take a number as a parameter and return True if the number is contained in the linked list, or False if the number is not in the list. Add code to your program to allow the user to enter a number, and search for the number in your linked list. Display a message to the user indicating if the number they entered was found in the list or not. In your logbook, include your code, and also output that shows you have tested the search function for a number in the list and a number not in the list. Example output: Please enter a number to search for in the list: 50 True Please enter a number to search for in the list: 28 False
Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here