Stack Implementation Using Array C Program
stack_array.txt
File size: 1.08 KB
File content type: text/plain
Category: Practical Files
Subject: Data Structure
#include<stdio.h>
#define MAXSIZE 5
void push();
int pop();
void peek();
int isEmpty();
int isFull();
int stk[MAXSIZE];
int top = -1;
void main() {
int value, choice;
while(1) {
printf("Enter choice.\n1. Push\n2. Pop\n3. Display\n4. Exit\n");
scanf("%d",&choice);
switch(choice) {
case 1: if(isFull()) {
printf("Cannot push. Overflow.\n");
break;
}
printf("Enter number\n");
scanf("%d",&value);
push(value);
break;
case 2: if(isEmpty()) {
printf("Cannot pop. Underflow.\n");
break;
}
value = pop();
printf("Value popped = %d\n",value);
break;
case 3: peek();
break;
case 4: return;
}
}
}
int isFull() {
if(top == MAXSIZE-1)
return 1;
return 0;
}
int isEmpty() {
if(top == -1)
return 1;
return 0;
}
void push(int value) {
stk[++top] = value;
}
int pop() {
int value = stk[top--];
return value;
}
void peek() {
int i;
for(i=0;i<=top;i++)
printf("%d ",stk[i]);
printf("\n");
}
Stack program in C using Array
Last Updated: July 16, 2022
Related
Reverse linked list C
Category: Practical FilesJuly 17, 2022
IPU Syllabus ECE 5th Sem
Category: SyllabusJuly 17, 2022
Manufacturing Process Question Paper Akash 2011-2014
Category: Question PapersJuly 16, 2022
ET Notes For 1st Semester
Category: NotesJuly 16, 2022
Sociology Important Topics
Category: NotesJuly 17, 2022
Sales Distribution Management Notes Unit 2
Category: NotesJuly 17, 2022
B.L. Thareja-Basic electrical Engineering (Vol.1)
Category: eBooksJuly 16, 2022
Corrosion Notes PDF
Category: NotesJuly 16, 2022
Sensor and Transducer Unit 1
Category: NotesJuly 17, 2022
POM Unit 3 Notes PDF
Category: NotesJuly 17, 2022