doubly linked list example

//insert link at the first location
void insertFirst(int key, int data) {

   //create a link
   struct node *link = (struct node*) malloc(sizeof(struct node));
   link->key = key;
   link->data = data;
	
   if(isEmpty()) {
      //make it the last link
      last = link;
   } else {
      //update first prev link
      head->prev = link;
   }

   //point it to old first link
   link->next = head;
	
   //point first to new first link
   head = link;
}

4.5
2
Hanner 80 points

                                    # Initialise 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 InsertToEmptyList(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 InsertToEnd(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 DeleteAtStart(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_prev = None;
    # Delete the elements from the end
    def delete_at_end(self):
        # Check if the List is empty
        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
        n = self.start_node
        while n.next is not None:
            n = n.next
        n.prev.next = None
    # Traversing and Displaying each element of the list
    def Display(self):
        if self.start_node is None:
            print("The list is empty")
            return
        else:
            n = self.start_node
            while n is not None:
                print("Element is: ", n.item)
                n = n.next
        print("\n")
# Create a new Doubly Linked List
NewDoublyLinkedList = doublyLinkedList()
# Insert the element to empty list
NewDoublyLinkedList.InsertToEmptyList(10)
# Insert the element at the end
NewDoublyLinkedList.InsertToEnd(20)
NewDoublyLinkedList.InsertToEnd(30)
NewDoublyLinkedList.InsertToEnd(40)
NewDoublyLinkedList.InsertToEnd(50)
NewDoublyLinkedList.InsertToEnd(60)
# Display Data
NewDoublyLinkedList.Display()
# Delete elements from start
NewDoublyLinkedList.DeleteAtStart()
# Delete elements from end
NewDoublyLinkedList.DeleteAtStart()
# Display Data
NewDoublyLinkedList.Display()

4.5 (2 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
doubly lined list doubly singly linked list represent doubly linked list with singly linked list why do we require doubly linked list doubly linked list to create and display doubly linked circular linked list given a doubly linked list doubly linked list circular when to use doubly linked list doubly linked vs singly linked list doubly linked list java example doubly linked list better than singly linked list the use of doubly linked list doubly linkedlist in java inbuilt doubly linked list explained doubel linked list program for doubly linked list implementing list using doubly linked doubly linked list graph what is false about doubly linked list what is the purpose of doubly linked list doubly linked list head dobuly linked list doublyy link list create a doubly linked list Doubly linked list is also called as doubly linked list insenode douby linked list example doubly linked list representation doubly linked list examples doubly linked list application linked list doubly applications of doubly linked list In doubly linked lis doubly linked list lru doubly linked list construction create doubly linked list Doubly Linked List operations doubly linked list functions example of doubly linked list doubly and singly linked list doubly linked list set doubly linked list is best doubly linked list gfg uses for doubly linked lists waht is doubly linked list e doubly linked list doubly linked list algorithm true about doubly linked list doubly linked list implementation implement doubly linked list how to make a doubly linked list which is true about doubly linked list simple doubly linked list implementation ordered doubly linked list doubly linked list vs singly linked list what does a doubly linked list implement doubly linked list real life example initializer list constructor for doubly linked list doubly linked list implementation java doubly linked lis doubly linked list algorithm simple how to use doubly linked list doubly linked list stl doubly linked list data structure Doubly Linked List dll = new Doubly Linked List(); how to create a doubly linked list 'doubly linked list why use doubly linked list doubly linked list code how does a doubly linked list work what is a doubly linked list doubly linked list type in a doubly linked list doubly linked list simplefied define doubly linked list doubly linked list definition package doubly linked list doubly linked list in c representation doubly linked list in go doubly linked list containing structure in c https://www.program to implement stack operations using linked list.tutorialspoint.com/data_structures_algorithms/doubly_linked_list_algorithm.htm Explain the various cases while deleting an element from a doubly linked list, with the help doubly linked list import prev and next in doubly linked list what is singly linked list and doubly linked list bidirecyinal link list traversing doubly linked list a simple doubly linked list bidirectional linked list structure of doubly linked list doubly link list computer world application of doubly linked list explain doubly linked list insertion in doubly linked list psudo code how to create a linked list linked list simple code fuctions for linked list Develop a program to implemetn following operations on a doubly linked list: i) insert before a given value different ways to implement doubly linked list doubly linked list c++ how to modify a doubly linked list node contains top function implementation using doubly linked list in c++ doubly linked list defination how to make a doubly linked list c++ doubly linked list applications In a doubly linked list how many nodes have atleast 1 node before and after it linked and doubly linked list double linked list implementatino algorithm explain doubly linked list with example creating the double linked list create a double linked list of size n where the information part of each node contain an integer doubly-linked list structure for doubly linked list c++ inserting into a doubly linked list c++ why the previous node of the doubly link list contains null pointer doubly lisnk list ) What is the procedure of printing all items in a reverse order from a doubly Linked list? Briefly explain. doublly linked list doubly linked linked list data structure double linked list code double-linked list linked list example all doubly link list methods "doubly linked list" complete implementation of a doubly linked list double liked list intoa list different ways to implement doubly link list two way linked list inserting a node in linked list two way doubly linked list or doubly linked list algorithm for insertion and deletion of a node in Doubly Linked List wat is a double lnlked list linked list doubly linked list doubly linked list prev and next how to define a double y linked list dboule linked list Insertion , Deletion operations with doubly linked lists. doube linked list double traversal doubly linked list what is doubly-linked list Doublylinked list properties of doubly linked list w linked list how doubly linked list look like insertion and deletion operation on doubly linked list in java algorithm for deletion and inertion in doubly linked list double link code doubly linked list diagram two way linked lists doubly node linked list doubly-linked nodes Doubly linked list program in data structure what is doubly linked list double linked list tutorial doubly linked list in data structure double link list doubley linked list It has nodes with a data field, a previous link field and a next link field. Double LL occupies less space than Single LL. More efficient to access the elements. In DLL, the traversal can be done using the previous node link or the next node link how to define double link list in a class c++ how to insert and delete elements from a doubly linked list doubly linked list example doublylinked list node double linked list example doubly liked node double linked list doubly linked list c++ tutorialspoint doubly linked list use a node pointer to output data stored within a double linked list in c++ example of a doubly linked list give the node structure of a doubly linked list
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source