Write a Python program to create a doubly-linked list. Append some items on the doubly-link list. Example: items.append_item('PHP') items.append_item('Python') items.append_item('C#') items.append_item('C++') items.append_item('Java') items.append_item('SQL') The program outputs the items by iterating through the list (in reverse order). Sample Output: Reverse list SQL Java C++ C# Python PHP

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

PYTHON DOUBLE LINK  LIST

Write a Python program to create a doubly-linked list.
Append some items on the doubly-link list.
Example:
items.append_item('PHP')
items.append_item('Python')
items.append_item('C#')
items.append_item('C++')
items.append_item('Java')
items.append_item('SQL')
The program outputs the items by iterating through the list (in reverse order).
Sample Output:
Reverse list
SQL
Java
C++
C#
Python
PHP
Transcribed Image Text:Write a Python program to create a doubly-linked list. Append some items on the doubly-link list. Example: items.append_item('PHP') items.append_item('Python') items.append_item('C#') items.append_item('C++') items.append_item('Java') items.append_item('SQL') The program outputs the items by iterating through the list (in reverse order). Sample Output: Reverse list SQL Java C++ C# Python PHP
You may also use this diagram as a guide for developing your program. Please note that you don't have to implement the print-forward method as shown in the diagram below.
Glass Node(object
<def_init_(self)
items = doubly_
linked_list0.
def init (self,
data=None,
next=None, prev=None)
class doubly_
Jinked_list(object)
def iter(self
def print_foward(self
def reverse(self
def append_item(self,
datā)
self. head = None
self.tail = None
self.count = 0
KEnd
current = self, head
items.append_item(PHP)
items.append item(Python)
items. append item('C#)
items. append item('C++)
items. append item(Java)
items. append_item(SQL)
print("Reverse list ")
items.reverse0
items.print_foward)
End
for node in self. iter0
current = self, head
self.data = data
self.next = next
self.prev = prev
new item = Node(data,
None, None)
End for
KEnd
current ?
current ?
End print(node)
KEnd
self. head is None ?
No
Yes
No
Yes
item val = current.data
Endlcurrent = current.next
yield item val
temp = current.next
current.next = current.prev
current.prev = temp
current = current.prev
Yes
No
temp = self.head
self.head = self.tail
self.tail = temp
KEnd
self.head = new item
self.tail = self. head
new item.prev = self.tail
self.tail.next = new item
self.tail = new item
End
self.count += 1
KEnd
Transcribed Image Text:You may also use this diagram as a guide for developing your program. Please note that you don't have to implement the print-forward method as shown in the diagram below. Glass Node(object <def_init_(self) items = doubly_ linked_list0. def init (self, data=None, next=None, prev=None) class doubly_ Jinked_list(object) def iter(self def print_foward(self def reverse(self def append_item(self, datā) self. head = None self.tail = None self.count = 0 KEnd current = self, head items.append_item(PHP) items.append item(Python) items. append item('C#) items. append item('C++) items. append item(Java) items. append_item(SQL) print("Reverse list ") items.reverse0 items.print_foward) End for node in self. iter0 current = self, head self.data = data self.next = next self.prev = prev new item = Node(data, None, None) End for KEnd current ? current ? End print(node) KEnd self. head is None ? No Yes No Yes item val = current.data Endlcurrent = current.next yield item val temp = current.next current.next = current.prev current.prev = temp current = current.prev Yes No temp = self.head self.head = self.tail self.tail = temp KEnd self.head = new item self.tail = self. head new item.prev = self.tail self.tail.next = new item self.tail = new item End self.count += 1 KEnd
Expert Solution
steps

Step by step

Solved in 3 steps with 1 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