20.13 LAB: Doubly linked list In this lab you are asked to complete the python code so that it: • Accepts integers as inputs from a user and appends them to the doubly linked list until the user enters -1 • Next, the user enters an integer and your code should: o find this in the doubly linked list o remove that node and all the nodes that comes after it in the list o If the node is not found in the doubly-linked-list, it should display: "Node not found", • Display the modified doubly linked list o if the doubly linked list is empty it should print "Empty!" For example, for following input 2

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, data):
        self.data = data
        self.next = None
        self.prev = None
        
# Empty Doubly Linked List
class DoublyLinkedList:
    def __init__(self):
        self.head = None

    def append(self, new_data): 
        if self.head == None:
            self.head = new_data
            self.tail = new_data
        else:
            self.tail.next = new_data
            new_data.prev = self.tail
            self.tail = new_data
 
    def printList(self):
        if(self.head == None):
            print('Empty!')
        else:
            node = self.head
            while(node is not None):
                print(node.data),
                node = node.next 

    def remove(self, current_node):
        successor_node = current_node.next
        predecessor_node = current_node.prev

        if successor_node is not None:
            successor_node.prev = predecessor_node

        if predecessor_node is not None:
            predecessor_node.next = successor_node

        if current_node is self.head:
            self.head = successor_node

        if current_node is self.tail:
            self.tail = predecessor_node
            
    def node_search(self,nodeA):
        #** Your code goes here **
        return self
        
    def chunck_removal(self,nodeA):
        #** Your code goes here **
         return self
        
if __name__ == '__main__': 
   
   #** Your code goes here **

20.13 LAB: Doubly linked list
In this lab you are asked to complete the python code so that it:
Accepts integers as inputs from a user and appends them to the doubly linked list until the user enters -1
• Next, the user enters an integer and your code should:
o find this in the doubly linked list
o remove that node and all the nodes that comes after it in the list
o If the node is not found in the doubly-linked-list, it should display: "Node not found",
Display the modified doubly linked list
o if the doubly linked list is empty it should print "Empty!"
For example, for following input
1
2
3
4
5
-1
6.
the output should be:
1
2
3
4
5
Transcribed Image Text:20.13 LAB: Doubly linked list In this lab you are asked to complete the python code so that it: Accepts integers as inputs from a user and appends them to the doubly linked list until the user enters -1 • Next, the user enters an integer and your code should: o find this in the doubly linked list o remove that node and all the nodes that comes after it in the list o If the node is not found in the doubly-linked-list, it should display: "Node not found", Display the modified doubly linked list o if the doubly linked list is empty it should print "Empty!" For example, for following input 1 2 3 4 5 -1 6. the output should be: 1 2 3 4 5
main.py
Load default template...
1 class Node:
2
def --init__(self, data):
self.data = data
4
self.next = None
self.prev = None
6.
7 # Empty Doubly Linked List
8 class DoublyLinkedList:
def -_init__(self):
10
self.head = None
11
12
def append(self, new_data):
13
if self.head
None:
self.head = new_data
self.tail = new_data
14
15
16
else:
17
self.tail.next = new_data
new_data.prev = self.tail
self.tail = new_data
18
19
20
def printlist(self):
if(self.head
print('Empty!')
else:
21
22
None):
23
24
25
node = self.head
while(node is not None):
print(node.data),
26
27
28
node = node.next
29
30
def remove(self, current_node):
31
successor_node = current_node.next
32
predecessor_node = current_node.prev
33
34
if successor_node is not None:
35
successor_node.prev = predecessor_node
36
37
if predecessor_node is not None:
predecessor_node.next = successor_node
38
39
40
if current_node is self.head:
41
self.head = successor_node
42
43
if current_node is self.tail:
44
self.tail = predecessor_node
45
46
def node_search(self,nodeA):
47
#** Your code goes here **
48
return self
49
def chunck_removal (self,nodeA):
#** Your code goes here **
50
51
52
return self
53
54 if -_name_-
_main__':
55
56
#** Your code goes here **
Transcribed Image Text:main.py Load default template... 1 class Node: 2 def --init__(self, data): self.data = data 4 self.next = None self.prev = None 6. 7 # Empty Doubly Linked List 8 class DoublyLinkedList: def -_init__(self): 10 self.head = None 11 12 def append(self, new_data): 13 if self.head None: self.head = new_data self.tail = new_data 14 15 16 else: 17 self.tail.next = new_data new_data.prev = self.tail self.tail = new_data 18 19 20 def printlist(self): if(self.head print('Empty!') else: 21 22 None): 23 24 25 node = self.head while(node is not None): print(node.data), 26 27 28 node = node.next 29 30 def remove(self, current_node): 31 successor_node = current_node.next 32 predecessor_node = current_node.prev 33 34 if successor_node is not None: 35 successor_node.prev = predecessor_node 36 37 if predecessor_node is not None: predecessor_node.next = successor_node 38 39 40 if current_node is self.head: 41 self.head = successor_node 42 43 if current_node is self.tail: 44 self.tail = predecessor_node 45 46 def node_search(self,nodeA): 47 #** Your code goes here ** 48 return self 49 def chunck_removal (self,nodeA): #** Your code goes here ** 50 51 52 return self 53 54 if -_name_- _main__': 55 56 #** Your code goes here **
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

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