_(self):         self.head = None         self.tail = None     def append(self, new

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

class Node:
    def __init__(self, initial_data):
        self.data = initial_data
        self.next = None


class LinkedList:
    def __init__(self):
        self.head = None
        self.tail = None

    def append(self, new_node):
        if self.head == None:
            self.head = new_node
            self.tail = new_node
        else:
            self.tail.next = new_node
            self.tail = new_node

    def prepend(self, new_node):
        if self.head == None:
            self.head = new_node
            self.tail = new_node
        else:
            new_node.next = self.head
            self.head = new_node

    def insert_after(self, current_node, new_node):
        if self.head == None:
            self.head = new_node
            self.tail = new_node
        elif current_node is self.tail:
            self.tail.next = new_node
            self.tail = new_node
        else:
            new_node.next = current_node.next
            current_node.next = new_node
            
    def remove_after(self, current_node):
        if (current_node == None) and (self.head != None):
            succeeding_node = self.head.next
            self.head = succeeding_node  
            if succeeding_node == None: # Remove last item
                self.tail = None
        elif current_node.next != None:
            succeeding_node = current_node.next.next
            current_node.next = succeeding_node
            if succeeding_node == None: # Remove tail
                self.tail = current_node
                    
    def display(self):
        node = self.head
        if (node == None):
            print('Empty!')
        while node != None:
            print(node.data, end=' ')
            node = node.next
            
    def remove_smallest_node(self):

         #*** Your code goes here!***
         # NOTE: this function will print out the information about the smallest node
         # before removing it

        
def Generate_List_of_LinkedLists(n):
    LLL = []
    
    #*** Your code goes here!***
    # NOTE: this function will read the input from the user for each of the lists and
    # generate the list
        
    return LLL
    
    
if __name__ == '__main__':  

    
        #*** Your code goes here!***

    
    

19.19 LAB: Linear Search
In this lab you are asked to complete the provided code so that it generates a list of singly-linked-lists (note: this will be a python list, where
each element of the list is a singly linked list). Your code should do the following:
To generate a list of singly linked lists, your code should accept the number of linked lists as an input
• Then, for each linked list, it should accept integers as nodes till the user enters -1
It should next display all the linked lists in the lists entered by the user
Next, it should accept a number - this is an index position for the list (a linked list)
• For the linked list in the index position supplied by the user, your code should find the node with the smallest value and delete it
o Your code should display "Empty!", if there is no nodes left in the linked list after removing the smallest node!
Finally, it should print the modified linked list
For example, when the input is:
3
7
-1
3
4
7
9.
-1
1
The output should be:
linked list [ 0 ]:
1 3 5 7
linked list [ 1 ]:
3 4 7 2 9
the smallest node is:
2
List 1 after removing the smallest node:
3 4 79
Note Make sure to check for the following possible user's mistakes
• if the user inputs a negative number as the number of linked lists in the list, your code should display: "Wrong input! try again:"; then,
let the user to input another number
Same for the Empty linked lists
Transcribed Image Text:19.19 LAB: Linear Search In this lab you are asked to complete the provided code so that it generates a list of singly-linked-lists (note: this will be a python list, where each element of the list is a singly linked list). Your code should do the following: To generate a list of singly linked lists, your code should accept the number of linked lists as an input • Then, for each linked list, it should accept integers as nodes till the user enters -1 It should next display all the linked lists in the lists entered by the user Next, it should accept a number - this is an index position for the list (a linked list) • For the linked list in the index position supplied by the user, your code should find the node with the smallest value and delete it o Your code should display "Empty!", if there is no nodes left in the linked list after removing the smallest node! Finally, it should print the modified linked list For example, when the input is: 3 7 -1 3 4 7 9. -1 1 The output should be: linked list [ 0 ]: 1 3 5 7 linked list [ 1 ]: 3 4 7 2 9 the smallest node is: 2 List 1 after removing the smallest node: 3 4 79 Note Make sure to check for the following possible user's mistakes • if the user inputs a negative number as the number of linked lists in the list, your code should display: "Wrong input! try again:"; then, let the user to input another number Same for the Empty linked lists
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY