Digital Assignment-1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

DATA STRUCTURES AND ALGORITHMS

(CSE2011)

DIGITAL ASSIGNMENT-1
NAME : NAMBAKKAM JAYANTH

Reg No : 20BCT0066

SLOT : L23 + L24

FACULTY NAME : SRIVANI A

LAB ASSIGNMENT
1) Stack applications

i) Infix to Postfix Conversion

CODE :
OUTPUT :
Enter the expression : a*b+c(ab+c)/a(bc)

a b * c a b c + a b c / +

...Program finished with exit code 0

Press ENTER to exit console.

ii) Evaluation of Postfix expression


CODE :

OUTPUT ;
Enter the expression : 12^3$3(58*2)*9

The result of expression 12^3$3(58*2)*9 = 9


...Program finished with exit code 0
Press ENTER to exit console.
2. Write a menu driven program to perform static implementation of a queue data structure with all possible
functions.

CODE :
OUTPUT :

QUEUE USING STACKS IMPLEMENTATION

1.ENQUEUE

2.DEQUEUE

3.DISPLAY

4.EXIT

Enter your choice : 1

Enter the data : 50

Enter your choice : 1

Enter the data : 30

Enter your choice : 1

Enter the data : 60

Enter your choice : 3

QUEUE ELEMENTS : 50 30 60

Enter your choice : 2

Enter your choice : 3

QUEUE ELEMENTS : 30 60

Enter your choice : 4

...Program finished with exit code 0

Press ENTER to exit console.


3. Write a program using arrays to perform insertion and deletion from both the ends of a Deque and
also display the contents of it based on the choice given by the user.

CODE :
OUTPUT :
1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Print
7.Exit

Enter your choice:1


Enter number of elements:3
Enter the data:1 2 3

1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Print
7.Exit

Enter your choice:2


Enter element to be inserted:2

1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Print
7.Exit

Enter your choice:3


Enter the element to be inserted:2

1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Print
7.Exit

Enter your choice:4


Element deleted is 2

1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Print
7.Exit

Enter your choice:5


Element deleted is 2

1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Print
7.Exit

Enter your choice:6

1
2
3

1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Print
7.Exit

Enter your choice:7

...Program finished with exit code 7


Press ENTER to exit console.
4 . Develop a code to implement a priority queue such the least element is processed first.

CODE :

OUTPUT :
Max-
Heap array: 9 5 4 3 2

After deleting an element: 9 5 2 3

...Program finished with exit code 0

Press ENTER to exit console.


5. Write a menu driven program to perform following functions in a singly linked list.
i) Insertion in the beginning of the list
ii) Insertion at the end of the list
iii) Insertion in a particular location of the list
iv) Deletion based on a particular value and location
v) Search an element**
vi) Reverse the list
vii) Count the number of even and odd numbers in the list**
CODE:
OUTPUT :
Number of nodes: 2

Enter the data of node 1: 22


Enter the data of node 2: 33

Choose your Choice


1 For insertion at beginning
2 for insertion at end
3 for insertion from any location
4 for deletion from any location
5 to reverse the order
6 to search for an element
7 to find odd and even number count
8 to display the list
9 to exit

Enter data to insert at beginning of the list: 11

Data = 11

Data = 22

Data = 33

Choose your Choice


1 For insertion at beginning
2 for insertion at end
3 for insertion from any location
4 for deletion from any location
5 to reverse the order
6 to search for an element
7 to find odd and even number count
8 to display the list
9 to exit

Enter data to insert at end of the list: 44


Data = 11
Data = 22
Data = 33
Data = 44

Choose your Choice


1 For insertion at beginning
2 for insertion at end
3 for insertion from any location
4 for deletion from any location
5 to reverse the order
6 to search for an element
7 to find odd and even number count
8 to display the list
9 to exit

insert new node

: 4

Enter the location=3

Node inserted
Data = 11
Data = 22
Data = 33
Data = 4
Data = 44

Choose your Choice


1 For insertion at beginning
2 for insertion at end
3 for insertion from any location
4 for deletion from any location
5 to reverse the order
6 to search for an element
7 to find odd and even number count
8 to display the list
9 to exit

4
Enter the location of the node after which you want to perform deletion

Data = 11
Data = 22
Data = 33
Data = 44

Choose your Choice


1 For insertion at beginning
2 for insertion at end
3 for insertion from any location
4 for deletion from any location
5 to reverse the order
6 to search for an element
7 to find odd and even number count
8 to display the list
9 to exit

Enter element to search: 22

22 found in the list at position 2

Choose your Choice


1 For insertion at beginning
2 for insertion at end
3 for insertion from any location
4 for deletion from any location
5 to reverse the order
6 to search for an element
7 to find odd and even number count
8 to display the list
9 to exit

Number of odd numbers = 2----


Number of even numbers = 2

Choose your Choice


1 For insertion at beginning
2 for insertion at end
3 for insertion from any location
4 for deletion from any location
5 to reverse the order
6 to search for an element
7 to find odd and even number count
8 to display the list
9 to exit

Data in the list


Data = 11
Data = 22
Data = 33
Data = 44

Choose your Choice


1 For insertion at beginning
2 for insertion at end
3 for insertion from any location
4 for deletion from any location
5 to reverse the order
6 to search for an element
7 to find odd and even number count
8 to display the list
9 to exit

Data = 44

Data = 33
Data = 22
Data = 11

Choose your Choice


1 For insertion at beginning
2 for insertion at end
3 for insertion from any location
4 for deletion from any location
5 to reverse the order
6 to search for an element
7 to find odd and even number count
8 to display the list
9 to exit

...Program finished with exit code 0

Press ENTER to exit console. .

You might also like