19.17 LAB: Doubly linked list In this lab you are asked to complete the program to do the following: Accept integers as inputs from the user and create/append them to a doubly linked list until the user enters -1 • Then swap the data in the head and the second node in the doubly linked list that has been created Note: you should be able to handle the following: If it is an empty linked list and in this case print 'Empty!" o your program should work for a linked list with only a single node - for such a list it should return the same list ie no swap! 377344.2021754.qx3zqy7 LAB 19.17.1: LAB: Doubly linked list 1/4 АCTIVITY main.py Load default template... 1 class Node: def -_init__(self, data): self.data = data 4 self.next = None 5 self.prev = None 7 8 # Empty Doubly Linked List 9 class DoublyLinkedList: def init__(self): self.head = None 10 11 12 13 # Inserts a new node on the front of list 14 def append(self, new_data): if self.head self.head = new_data self.tail = 15 16 None: 17 18 new_data 19 else: 20 self.tail.next = new_data new_data.prev = self.tail self.tail = new_data 21 22 23 24 def printlist(self): 25 node = self.head while(node is not None): print(node.data), node 26 27 28 node.next 29 30 def swap(self): 31 32 # ** Your code goes here ** 33 return 34 35 if --name__ _main__': 36 37 # ** Your code goes here ** 38 LL.swap) LL.printlist() 39 40 41 42

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
19.17 LAB: Doubly linked list
In this lab you are asked to complete the program to do the following:
Accept integers as inputs from the user and create/append them to a doubly linked list until the user enters -1
• Then swap the data in the head and the second node in the doubly linked list that has been created
Note: you should be able to handle the following:
If it is an empty linked list and in this case print 'Empty!"
o your program should work for a linked list with only a single node - for such a list it should return the same list ie no swap!
377344.2021754.qx3zqy7
LAB
19.17.1: LAB: Doubly linked list
1/4
АCTIVITY
main.py
Load default template...
1 class Node:
def -_init__(self, data):
self.data = data
4
self.next = None
5
self.prev
= None
7
8 # Empty Doubly Linked List
9 class DoublyLinkedList:
def init__(self):
self.head = None
10
11
12
13
# Inserts a new node on the front of list
14
def append(self, new_data):
if self.head
self.head = new_data
self.tail =
15
16
None:
17
18
new_data
19
else:
20
self.tail.next =
new_data
new_data.prev = self.tail
self.tail = new_data
21
22
23
24
def printlist(self):
25
node = self.head
while(node is not None):
print(node.data),
node
26
27
28
node.next
29
30
def swap(self):
31
32
# ** Your code goes here **
33
return
34
35 if --name__
_main__':
36
37
# ** Your code goes here **
38
LL.swap)
LL.printlist()
39
40
41
42
Transcribed Image Text:19.17 LAB: Doubly linked list In this lab you are asked to complete the program to do the following: Accept integers as inputs from the user and create/append them to a doubly linked list until the user enters -1 • Then swap the data in the head and the second node in the doubly linked list that has been created Note: you should be able to handle the following: If it is an empty linked list and in this case print 'Empty!" o your program should work for a linked list with only a single node - for such a list it should return the same list ie no swap! 377344.2021754.qx3zqy7 LAB 19.17.1: LAB: Doubly linked list 1/4 АCTIVITY main.py Load default template... 1 class Node: def -_init__(self, data): self.data = data 4 self.next = None 5 self.prev = None 7 8 # Empty Doubly Linked List 9 class DoublyLinkedList: def init__(self): self.head = None 10 11 12 13 # Inserts a new node on the front of list 14 def append(self, new_data): if self.head self.head = new_data self.tail = 15 16 None: 17 18 new_data 19 else: 20 self.tail.next = new_data new_data.prev = self.tail self.tail = new_data 21 22 23 24 def printlist(self): 25 node = self.head while(node is not None): print(node.data), node 26 27 28 node.next 29 30 def swap(self): 31 32 # ** Your code goes here ** 33 return 34 35 if --name__ _main__': 36 37 # ** Your code goes here ** 38 LL.swap) LL.printlist() 39 40 41 42
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education