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
Applied Physics 2 Unit 4 Band Theory and Semiconductor Notes
Category: NotesJuly 16, 2022
BL Thareja Volume 2 PDF
Category: eBooksJuly 16, 2022
IPU Entrepreneurship Development Notes Unit 2
Category: NotesJuly 17, 2022
Applied Chemistry I Lab File Hand Written
Category: Practical FilesJuly 16, 2022
BBA Computer Applications Notes Unit 1
Category: NotesJuly 16, 2022
Java Program to Find Factorial of a Number
Category: Practical FilesJuly 16, 2022
EDC Sem 2 2015 Aakash Question Paper (End Term)
Category: Question PapersJuly 16, 2022
Libre Office Notes Detailed - Unit 4
Category: NotesJuly 16, 2022
Business Mathematics Notes Unit 1
Category: NotesJuly 16, 2022
C++ Matrix Multiplication using OOP
Category: Practical FilesJuly 16, 2022