From 3f588d712175ddaaf0c2b50c901b792de3d44551 Mon Sep 17 00:00:00 2001 From: keshav Date: Tue, 21 Aug 2018 19:14:10 +0530 Subject: [PATCH 1/2] make programme for single linked list in python --- .../src/linked_list/linked_list.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 code/data_structures/src/linked_list/linked_list.py diff --git a/code/data_structures/src/linked_list/linked_list.py b/code/data_structures/src/linked_list/linked_list.py new file mode 100644 index 0000000000..1a3252420e --- /dev/null +++ b/code/data_structures/src/linked_list/linked_list.py @@ -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''' + From 03bc580e3e4590879b5114ec4b3ff566768a6b40 Mon Sep 17 00:00:00 2001 From: keshav Date: Wed, 22 Aug 2018 20:29:29 +0530 Subject: [PATCH 2/2] add python programme for dequeue data structure --- .../src/queue/double_ended_queue/deque.py | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 code/data_structures/src/queue/double_ended_queue/deque.py diff --git a/code/data_structures/src/queue/double_ended_queue/deque.py b/code/data_structures/src/queue/double_ended_queue/deque.py new file mode 100644 index 0000000000..1c60a7ae9a --- /dev/null +++ b/code/data_structures/src/queue/double_ended_queue/deque.py @@ -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()