You may find a doubly-linked list implementation below. Our first class is Node which we can make a new node with a given element. Its constructor also includes previous node reference prev and next node reference next. We have another class called DoublyLinkedList which has start_node attribute in its constructor as well as the methods such as: 1. insert_to_empty_list() 2. insert_to_end() 3. insert_at_index() Hints: Make a node object for the new element. Check if the index >= 0. If index is 0, make new node as head; else, make a temp node and iterate to the node previous to the index. If the previous node is not null, adjust the prev and next references. Print a message when the previous node is null. 4. delete_at_start() 5. delete_at_end() . 6. display() the task is to implement these 3 methods: insert_at_index(), delete_at_end(), display(). hint on how to start thee code # Initialize the Node class Node:             def __init__(self, data):                      self.item = data                        self.next = None                       self.prev = None # Class for doubly Linked List class DoublyLinkedList:            def __init__(self):                       self.start_node = None  # Insert Element to Empty list     def insert_to_empty_list(self, data):         if self.start_node is None:                 new_node = Node(data)                self.start_node = new_node    else:                 print("The list is empty")  # Insert element at the end     def insert_to_end(self, data):                # Check if the list is empty              if self.start_node is None:                        new_node = Node(data)                     self.start_node = new_node                     return          n = self.start_node          # Iterate till the next reaches NULL         while n.next is not None:                   n = n.next         new_node = Node(data)       n.next = new_node       new_node.prev = n      # Delete the elements from the start def delete_at_start(self):            if self.start_node is None:                    print("The Linked list is empty, no element to delete")            return           if self.start_node.next is None:                self.start_node = None                   return         self.start_node = self.start_node.next         self.start_node.prev = None   let the OUTPUT be: The list is empty Element is: 3 Element is: 10 Element is: 20 Element is: 30 Element is: 35 Element is: 38 Element is: 40 Element is: 50 Element is: 60 Element is: 10 Element is: 20 Element is: 30 Element is: 35 Element is: 38 Element is: 40 Element is: 50

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

You may find a doubly-linked list implementation below. Our first class is Node which we can make a new node with a given element. Its constructor also includes previous node reference prev and next node reference next.

We have another class called DoublyLinkedList which has start_node attribute in its constructor as well as the methods such as:

1. insert_to_empty_list() 2. insert_to_end() 3. insert_at_index()

Hints: Make a node object for the new element. Check if the index >= 0.
If index is 0, make new node as head; else, make a temp node and iterate to the node previous to the index.
If the previous node is not null, adjust the prev and next references. Print a message when the previous node is null.

4. delete_at_start()

5. delete_at_end() .

6. display()

the task is to implement these 3 methods: insert_at_index(), delete_at_end(), display().

hint on how to start thee code

# Initialize the Node

class Node:   

         def __init__(self, data):      

               self.item = data        

               self.next = None       

               self.prev = None

# Class for doubly Linked List

class DoublyLinkedList:    

       def __init__(self):       

               self.start_node = None

 # Insert Element to Empty list  

  def insert_to_empty_list(self, data):  

      if self.start_node is None:           

     new_node = Node(data)          

     self.start_node = new_node   

else:           

     print("The list is empty")

 # Insert element at the end   

 def insert_to_end(self, data):        

       # Check if the list is empty       

      if self.start_node is None:            

           new_node = Node(data)          

          self.start_node = new_node          

          return      

   n = self.start_node      

   # Iterate till the next reaches NULL    

    while n.next is not None:          

        n = n.next       

 new_node = Node(data)     

 n.next = new_node     

 new_node.prev = n 

    # Delete the elements from the start

def delete_at_start(self):       

    if self.start_node is None:          

         print("The Linked list is empty, no element to delete")            return       

   if self.start_node.next is None:       

        self.start_node = None          

        return      

  self.start_node = self.start_node.next      

  self.start_node.prev = None


 

let the OUTPUT be:

The list is empty
Element is: 3
Element is: 10
Element is: 20
Element is: 30
Element is: 35
Element is: 38
Element is: 40
Element is: 50
Element is: 60


Element is: 10
Element is: 20
Element is: 30
Element is: 35
Element is: 38
Element is: 40
Element is: 50

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
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