# Data Structures and Algorithm Lab

Topics: Linked list, Array data structure, Linked lists Pages: 56 (3230 words) Published: February 3, 2013
Department of Information Technology

LAB MANUAL

IT2205 – Data Structures and Algorithm Lab

INDEX

1. Array Implementation Of Stack

2. Application Of Stack – Conversion Of Infix To Postfix

3. Implementation Of Linear Queue Using Arrays

4. Array Implementation Of Circular Queue

5. Linked List Implementation Of Stack

6. Singly linked list – Linked list implementation

7. Doubly linked list – Linked list implementation

8. Polynomial Manipulation

9. Tree Traversals

10. Expression Tree

11. Priority Queue Using Heap

12. Hashing Technique

13. Dijkstra’s Algorithm

14. Back tracking algorithm – knap sack problem

Ex. no.: 1

Date:

ARRAY IMPLEMENTATION OF STACK

Aim

To write a C-program to implement stack using array data structure.

And perform the following stack operations

1. POP

2. PUSH

3. PEEP

Algorithm

STEP 1:Start

STEP 2:Initialize stack, will=1,i, num

STEP 3:Add element in stack

PUSH(S,TOP,X)

3.a. [Check overflow condition]

If(TOP>=N) then

Write(“Stack is full”)

3.b. [Insert element]

[Increment TOP]

TOP =1)

post[j++]=pop();

push(2);

break;

case '*':

while(stack[top]>=3)

post[j++]=pop();

push(3);

break;

case '/':

while(stack[top]>=3)

post[j++]=pop();

push(4);

break;

case '^':

while(stack[top]>=4)

post[j++]=pop();

push(5);

break;

case '(':

push(0);

break;

case ')':

while(stack[top]!=0)

post[j++]=pop();

top--;

break;

default:

post[j++]=inf[i];

}

}

while(top>0)

post[j++]=pop();

printf("\nPostfix Expression is :: %s",post);

}

void push(int ele)

{

top++;

stack[top]=ele;

}

char pop()

{

char e;

e=stack[top];

top--;

switch(e)

{

case 1:

e='+';

break;

case 2:

e='-';

break;

case 3:

e='*';

break;

case 4:

e='/';

break;

case 5:

e='^';

break;

}

return(e);

}

Output:

Enter the infix expression :: (a+b)/(c*d)

Postfix Expression is :: ab+cd*/

Manual Calculation

| SE EXPRESSION | STACK | RESULT FIELD | |( |( | | |A | |A | |+ |+,( |A | |B |+,( |AB | |) |),( |AB+ | |/ |/ |AB+ | |( |(,/ | | |C |(,/ |AB+C | |- |-,(,/...

Please join StudyMode to read the full document