×
BE SO GOOD THEY CAN'T IGNORE YOU
--Your friends at LectureNotes
Close

Data Structure using C

by Thirumurugan SThirumurugan S
Type: PracticalViews: 9Uploaded: 14 days ago

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Thirumurugan S
Thirumurugan S
DATA STRUCTURE LAB MANUAL
DATA STRUCTURE LABORATORY 1 Implementation of all the data structures specified in Data Structures theory subject(STACK,QUEUE,LINKED LIST). 2 Implement applications like conversion of arithmetic expressions from infix to postfix and evaluation of Postfix expressions. 3 Implementation of Linked Dictionary. 4 Implementation of Searching using Binary Search trees. 5 Implementation of Quick sort algorithm. 6 Implementation of Merge sort algorithm. 7 Implementation of Graph search algorithms. 8 Implementation of Minimal spanning tree algorithms. 9 Implementation of Shortest path algorithm. 10 Implementation of Heap structure.
1.Implementation of all the data structures specified in Data Structures theory subject .(STACK,QUEUE,LINKED LIST) STACK USING ARRAY Aim: To write a program to create a Stack and manipulate it using one dimensional Array. Algorithm: 1. Start 2. Declare an one dimensional array variable 3. Using Switch case statement select one appropriate operation a. PUSH: i. Read an element ii. Store it at the top of the stack iii. Increment the TOS b. POP i. Read the element from the top of the stack ii. Display it iii. Decrement the TOS c. PEEK i. Read the element from the top of the stack ii. Display it 4. Stop Program Code: #include<stdio.h> #include<conio.h> #define SIZE 10 int stack[SIZE]; int top=-1,item; void main() { void push(); void pop(); void peep(); void display(); int ch; char ch1; clrscr(); printf("\n\n\t\tSTACK USING ARRAY\n"); printf("\t\t*****************\n"); do { printf("\n1.PUSH OPERATION"); printf("\n2.POP OPERATION"); printf("\n3.PEEP OPERATION"); printf("\n4.DISPLAY OPERATION"); printf("\n5.EXIT\n"); printf("\n Enter ur choice:"); scanf("%d",&ch); switch(ch) {
case 1: push(); break; case 2: pop(); break; case 3: peep(); break; case 4: display(); break; case 5: exit(); } printf("\n\n Do u want to continue:"); fflush(stdin); scanf("%c",&ch1); }while(ch1=='y'); } void push() { printf("\n Enter the element to be inserted:"); scanf("%d",&item); fflush(stdin); if(top==SIZE-1) { printf("\nSTACK IS FULL\n"); return; } else { top=top+1; stack[top]=item; } } void pop() { if(top<0) { printf("\nSTACK IS EMPTY\n"); return; } else { item=stack[top]; top=top-1; printf("\n Deleted element is=%d",item); } } void peep() { if(top<0) { printf("\n STACK IS EMPTY\n"); return; }

Lecture Notes