-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Create singly_LinkedList.py #110
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d5fd222
Create singly_LinkedList.py
avkaran-singh fcd5ac1
Update singly_LinkedList.py
avkaran-singh d784139
Update singly_LinkedList.py
avkaran-singh 3ee70b3
Update singly_LinkedList.py
avkaran-singh 31a73b4
Update singly_LinkedList.py
avkaran-singh ea5e3c4
Update singly_LinkedList.py
avkaran-singh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,110 @@ | ||
class Node: #create a Node | ||
def __int__(self,data): | ||
self.data=data #given data | ||
self.next=None #given next to None | ||
|
||
|
||
|
||
|
||
class Linked_List: | ||
pass | ||
def insert_tail(Head,data): #insert the data at tail | ||
tamp=Head | ||
if(tamp==None): | ||
newNod=Node() #create newNode Node type and given data and next | ||
newNod.data=data | ||
newNod.next=None | ||
Head=newNod | ||
|
||
else: | ||
while tamp.next!=None: #reaches the last Node | ||
tamp=tamp.next | ||
newNod = Node() #create a new node | ||
newNod.data = data | ||
newNod.next = None | ||
tamp.next=newNod #put the newnode into last node | ||
|
||
return Head | ||
def insert_head(Head,data): | ||
tamp = Head | ||
if (tamp == None): | ||
newNod = Node() #create a new Node | ||
newNod.data = data | ||
newNod.next = None | ||
Head = newNod #make new node to Head | ||
# print(Head.data) | ||
return Head | ||
else: | ||
newNod = Node() | ||
newNod.data = data | ||
newNod.next = Head #put the Head at NewNode Next | ||
Head=newNod # make a NewNode to Head | ||
# print(tamp.data) | ||
return Head | ||
|
||
|
||
|
||
def Print(Head): #print every node data | ||
tamp=Node() | ||
tamp=Head | ||
while tamp!=None: | ||
print(tamp.data) | ||
tamp=tamp.next | ||
|
||
|
||
|
||
def delete_head(Head): #delete from head | ||
if Head==None: | ||
print("List is empty cannot delete") | ||
|
||
else: | ||
Head=Head.next | ||
|
||
return Head #return new Head | ||
|
||
|
||
|
||
def delete_tail(Head): #delete from tail | ||
if Head==None: | ||
print("List is empty cannot delete") | ||
else: | ||
tamp = Node() | ||
tamp = Head | ||
while (tamp.next).next!= None: #reach tha 2nd last element | ||
tamp = tamp.next | ||
tamp.next=None #delet the last element by give next None to 2nd last Element | ||
|
||
|
||
|
||
def isEmpty(Head): | ||
if(Head==None): #check Head is None or Not | ||
print("list is empty") | ||
return True #return Ture if it is none | ||
else: | ||
print("Not empty") | ||
return False #check False if it's not none | ||
|
||
|
||
|
||
##check | ||
|
||
Head=None | ||
Head=Linked_List.insert_tail(Head,5) | ||
Head=Linked_List.insert_tail(Head,6) | ||
Head=Linked_List.insert_head(Head,7) | ||
Head=Linked_List.insert_head(Head,9) | ||
|
||
Linked_List.Print(Head) | ||
|
||
print("delete_tail") | ||
Linked_List.delete_tail(Head) | ||
Linked_List.Print(Head) | ||
|
||
|
||
print("delete_head") | ||
Head=Linked_List.delete_head(Head) | ||
Linked_List.Print(Head) | ||
|
||
Linked_List.isEmpty(Head) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove these blank lines please