Reverse the stack by R4R Team


program-

#include< stdio.h>
#include< conio.h>
#define max 50
int stack1[max],top1=-1;
int stack2[max],top2=-1;

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

void traverse1()
{
int i;
printf("First Stack is :\n");
for(i=top1;i>=0;i--){
printf("%d ",stack1[i]);
}
}

void traverse2()
{
int i;
printf("Second Stack is :\n");
for(i=top2;i>=0;i--)
{
printf("%d ",stack2[i]);
}
}

void reversecopy()
{
int i;
for(i=top1;i>=0;i--)
{
top2++;
stack2[top2]=stack1[i];
}
}

void main()
{
clrscr();
create();
traverse1();
reversecopy();
traverse2();
getch();
}


output-

Enter Number
2
Continue(y/n)
Enter Number
1
Continue(y/n)
Enter Number
9
Continue(y/n)
Enter Number
3
Continue(y/n)
Enter Number
6
Continue(y/n)
First stack is :
6 3 9 1 2
Second Stack is :
2 1 9 3 6




Leave a Comment:
Search
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!