Computer Science, asked by akashp12, 6 months ago

Write a C program to implement stack using array .

Write C Program​

Answers

Answered by rohinithirumalai59
1

Answer:

I hope it helps you

please mark me as brainy please mark me

Explanation:

#include<stdio.h>

void push(char element, char stack[], int *top, int stackSize){

if(*top == -1){

stack[stackSize - 1] = element;

*top = stackSize - 1;

}

else if(*top == 0){

printf("The stack is already full. \ n")

Answered by unknownRU
0

Hope it helps!

Mark me as Brainlist!

Program of stack using array in c programming

#include<stdio.h>

#include<conio.h>

#define MAX 5

int a[MAX],top=-1;

void push();

void pop();

void display();

int main()

{

int ch;

printf("1.push or insert\n");

printf("2.pop or delete\n");

printf("3.display\n");

printf("4.end program\n");

while(1){

printf("\nEnter choice");

scanf("%d",&ch);

switch(ch){

case 1:{

push();

break;

}

case 2:{

pop();

break;

}

case 3:{

display();

break;

}

case 4:{

exit(0);}

default:

{

printf("wrong choice");

}}

}}

void push(){

int data;

if(top==MAX-1){

printf("\n overflow or stack is full");

}

else{

printf("enter element to be pushed:");

scanf("%d",&data);

top++;

a[top]=data;

}}

void pop(){

if(top==-1){

printf("underflow or stack is empty");

}

else{

printf("popped element: %d",a[top]);

top--;

}}

void display (){

int i;

if(top>0){

printf("elements:");

for(i=top;i>0;i--)

printf("\n %d",a[i]);

}

else{

printf("the stack is empty");

}}

Similar questions