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
Services Marketing Notes Unit 1 PDF
Category: NotesJuly 17, 2022
Business Communication Notes PDF
Category: NotesJuly 17, 2022
IPU Syllabus ECE 5th Sem
Category: SyllabusJuly 17, 2022
Digital System Design Notes PDF 2019
Category: NotesJuly 17, 2022
Decision Table Testing Next Date C Program
Category: Practical FilesJuly 16, 2022
Manufacturing Processes Notes (Welding and Sheet Metal)
Category: NotesJuly 16, 2022
Business Policy Notes Unit 1 PDF
Category: NotesJuly 17, 2022
Laplace Transform Notes PDF
Category: NotesJuly 16, 2022
Communication System Lab File (Hand Written)
Category: Practical FilesJuly 16, 2022
Goods and Services Tax Notes Unit 4
Category: NotesJuly 17, 2022