#include<stdio.h>
#include"stack.h" //given before
void insertAtBottom(struct stack *S,int data)
{
if(isEmpty(S))
{
push(S,data);
return;
}
if(topElement(S) >data)
{
int temp=pop(S);
insertAtBottom(S,data);
push(S,temp);
}
else
{
push(S,data);
}
}
void Sort_Stack(struct stack *S)
{
int data;
if(isEmpty(S))
{
return ;
}
else
{
data=pop(S);
Sort_Stack(S);
insertAtBottom(S,data);
}
}
int main()
{
struct stack s;
int i=0,x;
initstack(&s);
printf("Before Reverse:\n");
while(i<6)
{
printf("Enter value:");
scanf("%d",&x);
push(&s,x);
i++;
}
Sort_Stack(&s);
printf("After Reverse:");
display(&s);
return 0;
}
#include"stack.h" //given before
void insertAtBottom(struct stack *S,int data)
{
if(isEmpty(S))
{
push(S,data);
return;
}
if(topElement(S) >data)
{
int temp=pop(S);
insertAtBottom(S,data);
push(S,temp);
}
else
{
push(S,data);
}
}
void Sort_Stack(struct stack *S)
{
int data;
if(isEmpty(S))
{
return ;
}
else
{
data=pop(S);
Sort_Stack(S);
insertAtBottom(S,data);
}
}
int main()
{
struct stack s;
int i=0,x;
initstack(&s);
printf("Before Reverse:\n");
while(i<6)
{
printf("Enter value:");
scanf("%d",&x);
push(&s,x);
i++;
}
Sort_Stack(&s);
printf("After Reverse:");
display(&s);
return 0;
}