Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

linke dlists in python

# A simple Python program to introduce a linked list
  
# Node class
class Node:
  
    # Function to initialise the node object
    def __init__(self, data):
        self.data = data  # Assign data
        self.next = None  # Initialize next as null
  
  
# Linked List class contains a Node object
class LinkedList:
  
    # Function to initialize head
    def __init__(self):
        self.head = None
  
  
# Code execution starts here
if __name__=='__main__':
  
    # Start with the empty list
    llist = LinkedList()
  
    llist.head = Node(1)
    second = Node(2)
    third = Node(3)
  
    '''
    Three nodes have been created.
    We have references to these three blocks as head,
    second and third
  
    llist.head        second              third
         |                |                  |
         |                |                  |
    +----+------+     +----+------+     +----+------+
    | 1  | None |     | 2  | None |     |  3 | None |
    +----+------+     +----+------+     +----+------+
    '''
  
    llist.head.next = second; # Link first node with second 
  
    '''
    Now next of first Node refers to second.  So they
    both are linked.
  
    llist.head        second              third
         |                |                  |
         |                |                  |
    +----+------+     +----+------+     +----+------+
    | 1  |  o-------->| 2  | null |     |  3 | null |
    +----+------+     +----+------+     +----+------+ 
    '''
  
    second.next = third; # Link second node with the third node
  
    '''
    Now next of second Node refers to third.  So all three
    nodes are linked.
  
    llist.head        second              third
         |                |                  |
         |                |                  |
    +----+------+     +----+------+     +----+------+
    | 1  |  o-------->| 2  |  o-------->|  3 | null |
    +----+------+     +----+------+     +----+------+ 
    '''
Comment

PREVIOUS NEXT
Code Example
Python :: django query filter less than 
Python :: NMF cosine similarities 
Python :: unittest only run test if other tests passes 
Python :: python loop take out element backwardly 
Python :: what is topic modelling in nlp 
Python :: fastai read data from image folders 
Python :: how to calculate the area and perimeter of a shape in python 
Python :: Customizing multiple plots in the same figure 
Python :: how to prefix numbers with zero in python 
Python :: how to choose appropriate graph for dataset visualization 
Python :: pythonanywhere API example 
Python :: Tree : Top View 
Python :: 1041 uri solution 
Python :: Fill NaN with the first valid value starting from the rightmost column, then extract first column 
Python :: run thread that inputs into queue and other threads process that python 
Python :: replace python enter number of characters 
Python :: change form type flask from text to selection flask admin 
Python :: index is datetime and i want the row number 
Python :: como inserir um elemento num set em python 
Python :: spacy vietnamese 
Python :: django test postgres extensions intarray 
Python :: why static kwyword not in python 
Python :: how to tokenize a dataframe in python csv 
Python :: django clodinarystorage 
Python :: template strings in python 
Python :: Return an RDD created by coalescing all elements within each partition into a list. 
Python :: open chrome with python stack overflow 
Python :: assigning a value to a character in string or text file in python 
Python :: python argparse only allow certain values 
Python :: how to find all the installed packages in python 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =