Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added linked list code #181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions Searching-algo/linked-list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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.next = second; # Link first node with second

'''
Now next of first Node refers to second. So they
both are linked.
'''

second.next = third; # Link second node with the third node

'''
Now next of second Node refers to third. So all three
nodes are linked.

'''