forked from OpenGenus/cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request OpenGenus#3654 from import-keshav/master
Single linked list programme in python
- Loading branch information
Showing
2 changed files
with
101 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,52 @@ | ||
''' simple prpgrame for single linked list in python ''' | ||
|
||
|
||
Head=None ''' head node, initilase Null or none ''' | ||
Tail=None ''' tail node, initilase Null or none ''' | ||
|
||
''' object class ''' | ||
|
||
class A: | ||
def __init__(self): | ||
self.data=0 | ||
self.next=None | ||
|
||
''' function for creating node ''' | ||
|
||
def create_node(): | ||
t=A() | ||
return t | ||
|
||
''' function for inserting node ''' | ||
|
||
def insert_node(): | ||
global Head,Tail | ||
temp=create_node() | ||
print("Enter your value",end="\n") | ||
a=input() | ||
temp.data=a | ||
if(Head==None): | ||
Head=temp | ||
Tail=temp | ||
else: | ||
Tail.next=temp | ||
Tail=temp | ||
|
||
''' function for traversing linked list ''' | ||
|
||
def traverse(Head): | ||
t=Head | ||
while(t.next!=None): | ||
print(t.data,end="\n") | ||
t=t.next | ||
print(t.data,end="\n") | ||
|
||
''' main function ''' | ||
|
||
insert_node() | ||
insert_node() | ||
insert_node() | ||
insert_node() | ||
|
||
traverse(Head) ''' passing head node for tarversing''' | ||
|
49 changes: 49 additions & 0 deletions
49
code/data_structures/src/queue/double_ended_queue/deque.py
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,49 @@ | ||
''' python programme for showing dequeue data sturcture in python ''' | ||
|
||
|
||
''' class for queue type data structure having following methods''' | ||
|
||
class Queue(): | ||
def __init__(self): | ||
self.array=[] # ''' initialise empty array ''' | ||
|
||
def front_enqueue(self,data): # ''' adding element from front ''' | ||
self.array.insert(0,data) | ||
|
||
def front_dequeue(self): # ''' deleting element from front ''' | ||
k=self.array[0] | ||
del self.array[0] | ||
|
||
def rear_dequeue(self): # ''' deleting element from rear ''' | ||
k=self.array.pop() | ||
print(k) | ||
|
||
def rear_enqueue(self,data): # ''' adding element from rear ''' | ||
self.array.append(data) | ||
|
||
def traverse(self): # ''' priting all array ''' | ||
print(self.array) | ||
|
||
queue=Queue() # ''' initialise Queue instance ''' | ||
queue.front_enqueue(5) | ||
queue.front_enqueue(4) | ||
queue.front_enqueue(3) | ||
queue.front_enqueue(2) | ||
|
||
queue.traverse() | ||
|
||
queue.front_dequeue() | ||
|
||
queue.traverse() | ||
|
||
queue.rear_enqueue(5) | ||
queue.rear_enqueue(4) | ||
queue.rear_enqueue(3) | ||
queue.rear_enqueue(2) | ||
|
||
queue.traverse() | ||
|
||
queue.rear_dequeue() | ||
queue.rear_dequeue() | ||
|
||
queue.traverse() |