Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Double-Linked List Python

# node structure
class Node:
  def __init__(self, data):
    self.data = data
    self.next = None
    self.prev = None

#class Linked List
class LinkedList:
  def __init__(self):
    self.head = None

  #Add new element at the start of the list
  def push_front(self, newElement):
    newNode = Node(newElement)
    if(self.head == None):
      self.head = newNode
      return
    else:
      self.head.prev = newNode
      newNode.next = self.head
      self.head = newNode

  #display the content of the list
  def PrintList(self):
    temp = self.head
    if(temp != None):
      print("The list contains:", end=" ")
      while (temp != None):
        print(temp.data, end=" ")
        temp = temp.next
      print()
    else:
      print("The list is empty.")

# test the code                  
MyList = LinkedList()

#Add three elements at the start of the list.
MyList.push_front(10)
MyList.push_front(20)
MyList.push_front(30)
MyList.PrintList()
Comment

double linked list python

Doubly Linked List carry a link element that is called first and last. Every link carries a data field(s) and two link fields called next and prev. Each link is linked with its next link using its next link. Each link is linked with its previous link using its previous link.
Comment

PREVIOUS NEXT
Code Example
Python :: Print feature importance per feature 
Python :: import starting with number 
Python :: how to check columns with the numerical values 
Python :: How to check if variable exists in a column 
Python :: Python Tkinter Scrollbar Widget Syntax 
Python :: calculate iou of two rectangles 
Python :: The get() method on Python dicts and its "default" arg 
Python :: flask env variable 
Python :: web parser python 
Python :: saving to PIL image to s3 
Python :: is boolean number python 
Python :: how to fix value error in model.fit 
Python :: Membership in a list 
Python :: python variable and data structure 
Python :: python pod status phase 
Python :: clear list in python 
Python :: round to 0 decimal 
Python :: Analyzing code samples, comparing more than 2 numbers 
Python :: increase tkinter window resolution 
Python :: python Access both key and value without using items() 
Python :: python get screen dpi 
Python :: how a 16 mp camera looks like 
Python :: machine earning to predict sentimentanalysis python 
Python :: Python Textfeld lköschen 
Python :: if len(i1.getbands()) == 1 
Python :: no lapack/blas resources found scipy 
Python :: dictionnaire 
Python :: varianza en pandas 
Python :: python type conversion 
Python :: WARNING: Ignoring invalid distribution -pencv-python 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =