0% found this document useful (0 votes)
24 views2 pages

Diffreence

The document provides implementations for stack and queue data structures in Python, detailing functions for operations such as push, pop, enqueue, and dequeue. It includes methods for checking the top or front elements, displaying contents, and determining the length of the structures. Additionally, it introduces a deque with functions for inserting and deleting from both ends.

Uploaded by

zunerakulsum29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Diffreence

The document provides implementations for stack and queue data structures in Python, detailing functions for operations such as push, pop, enqueue, and dequeue. It includes methods for checking the top or front elements, displaying contents, and determining the length of the structures. Additionally, it introduces a deque with functions for inserting and deleting from both ends.

Uploaded by

zunerakulsum29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

STACK QUEUE

def push(): def enqueue():


ele = int(input(“Enter the elements ”)) ele=int(input(“Enter the element ”))
[Link] (ele) [Link](element)

def pop(): def dequeue():


if stack == [ ] : if q == []:
print("Stack is empty or underflow") print(“Queue is empty”)
else: else :
print(“Deleted element is ”,[Link]()) print(“Deleted item is ”, [Link](0))

def peek(): def peek():


if stack == [ ]: if q == []:
print("Stack is empty ") print("Queue is empty.")
else: else:
print(“Peek item is ”, stack[-1]) print("Peak element is :", q[0])
def display(): def display():
if stack == [ ]: if queue == [ ]:
print("Stack is empty ") print("queue is empty ")
else: else:
print(“Items in the stack are ”, stack[ : : -1]) print(“Items in the queue are ”, q)
def length(): def length():
print(len(stack)) pirnt(len(q))

QUEUE DEQUEUE
def insertRear():
def enqueue(): ele=int(input(“Enter the element ”))
ele=int(input(“Enter the element ”)) [Link](ele)
[Link](element)
def insertFront():
ele=int(input(“Enter the element ”))
[Link](0,ele)

def deleteFront():
def dequeue(): if dq == []:
if q == []: print("Deque is empty")
print(“Queue is empty”) else:
else : print([Link](0))
print(“Deleted item is ”, [Link](0))
def deleteRear():
if d if q == []:
print("Deque empty")
else:
print([Link]())
def peek(): def getRear():
if q == []: if dq == []:
print("Queue is empty.") print("Queue empty")
else: else:
print("Peak element is :", q[0]) print(“rear item is ”, dq[-1])
def getFront():
if dq == []:
print("Deque is empty")
else:
print(“front item is ”,dq[0])

You might also like