-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LINKED LIST IN PYTHON yshshrm#1377 CLOSES
- Loading branch information
1 parent
ac97dbe
commit 5ff19b4
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# A simple Python program for implementing linked list in python | ||
# Node class | ||
class Node: | ||
# Function to initialise the node object | ||
def __init__(self, data): | ||
self.data = data # Assign data | ||
self.next = None | ||
class LinkedList: | ||
def __init__(self): | ||
self.head = None | ||
# This function prints contents of linked list | ||
# starting from head | ||
def printList(self): | ||
temp = self.head | ||
while (temp): | ||
print temp.data, | ||
temp = temp.next | ||
# Code execution starts here | ||
if __name__=='__main__': | ||
# Start with the empty list | ||
llist = LinkedList() | ||
llist.head = Node(1) | ||
second = Node(2) | ||
third = Node(3) | ||
|
||
llist.head.next = second; # Link first node with second | ||
second.next = third; # Link second node with the third node | ||
|
||
llist.printList() |