Hit this exam harder than you have ever done before.
--Your friends at LectureNotes

Lab Manuals for Data Structure using C - DS By Thirumurugan S

  • Data Structure using C - DS
  • Practical
  • Uploaded 5 months ago
Thirumurugan S
Thirumurugan S
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-2

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.

Text from page-3

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) {

Text from page-4

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; }

Text from page-5

else { printf("\n The top element is: %d",stack[top]); } } void display() { int i; if(top<0) { printf("\n STACK IS EMPTY\n"); return; } else { printf("\n ELEMENTS ARE\n"); i=top; while(i>=0) { printf("%d\n",stack[i]); --i; } } }

Lecture Notes