0% found this document useful (0 votes)
18 views13 pages

DS Practical 1-9 INPUTS

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

DS Practical 1-9 INPUTS

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

Prac cal-01A: WAP to implement Stack.

Prac cal-01B: WAP to implement list ADT.


Prac cal-02: WAP to implement stack data structure.
Prac cal-03: WAP to implement singly linked list with various opera ons.
Prac cal-04: WAP to implement doubly linked list with inser on, dele on, & traversal.

#ini alise the node

class Node:

def __init__(self,data):

self.item=data

self.next=None

self.prev=None

#class for doubly linked list

class doublyLinkedList:

def __init__(self):

self.start_node=None

#insert element to empty list

def InsertToEmptyList(self,data):

if self.start_node is None:

new_node=Node(data)

self.start_node=new_node

else:

print("The list is empty")

#Insert element at the end

def InsertToEnd(self,data):

#check if the list is empty

if self.start_node is None:

new_node=Node(data)

self.start_node=new_node

return

n=self.start_node

#iterate ll the next reaches null

while n.next is not None:

n=n.next

new_node=Node(data)

n.next=new_node
new_node.prev=n

#delete the elements from the start

def DeleteAtStart(self):

if self.start_node is None:

print("The linked list is empty,no element to delete")

return

if self.start_node.next is None:

self.start_node=None;

#Delete the elements from the end

def delete_at_end(self):

#check if the list is empty

if self.start_node is None:

print("The linked list is empty,no element to delete")

return

if self.start_node.next is None:

self.start_node=None

return

n=self.start_node

while n.next is not None:

n=n.next

n.prev.next=None

#Traversing and displaying each element of the list

def Display(self):

if self.start_node is None:

print("The list is empty")

return

else:

n=self.start_node

while n is not None:

print("Element is:",n.item)

n=n.next
print("\n")

#Create a new doubly linked list

NewDoublyLinkedList=doublyLinkedList()

#Insert the element to empty list

NewDoublyLinkedList.InsertToEmptyList(10)

#Insert the element at the end

NewDoublyLinkedList.InsertToEnd(20)

NewDoublyLinkedList.InsertToEnd(30)

NewDoublyLinkedList.InsertToEnd(40)

NewDoublyLinkedList.InsertToEnd(50)

NewDoublyLinkedList.InsertToEnd(60)

#display data

NewDoublyLinkedList.Display()

#delete elements from the start

NewDoublyLinkedList.DeleteAtStart()

#Delete elements from the end

NewDoublyLinkedList.delete_at_end()

#display data

NewDoublyLinkedList.Display()
Prac cal-05A: WAP to implement queue Abstract Data Type(ADT).

Prac cal-05B: WAP to implement Dequeue Abstract Data Type(ADT).


Prac cal-06: WAP to implement Priority Queue.
Prac cal-07A: WAP to implement Binary tree with inser on & dele on.

,
Prac cal-07B: WAP to implement tree traversal.
Prac cal-08A: WAP to implement Graph Data Structure.

Prac cal-08B: WAP to implement Graph Traversing.


Prac cal-09: WAP to implement Hash Table.

You might also like