Make Stack by Array by R4R Team

Here We create a Stack with the use of the array.

program-

#include< stdio.h>
#include< conio.h>
#define max 50
int stack[max],top=-1;

void create()
{
char ch;
do
{
top++;
printf("Enter Number\n");
scanf("%d",&stack[top]);
printf("Continue(y/n)?\n");
ch=getch();
}while(ch=='y');
}

void traverse()
{
int i;
printf("Stack is :\n");
for(i=top;i>=0;i--){
printf("%d ",stack[i]);
}
}

void main()
{
clrscr();
create();
traverse();
getch();
}


output-

Enter Number
2
Continue(y/n)?
Enter Number
3
Continue(y/n)?
Enter Number
4
Continue(y/n)?
Enter Number
6
Continue(y/n)?
Enter Number
9
Continue(y/n)?
Stack is :
9 6 4 3 2

-In this program, we have two functions create() and traverse().
-create() function are used tp create a stack
-traverse() function are used to traverse the stack from top to bottom.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!