Ejemplo n.º 1
0
void ReverseStack(int stack[],int top) {
    if(top != -1){
	   int this = stack[top];
	   top--;
	   ReverseStack(stack,top);
	   AddToStackBottom(stack, top, this);
	}	
Ejemplo n.º 2
0
void ReverseStack(Stack *s)
{
    if(isempty(s))  return;
    int data;
    data=pop(s);
    ReverseStack(s);
    InsertAtbottom(s,data);
}
Ejemplo n.º 3
0
//O(n^2) time and O(n) space complexity
//Reverse stack using only push pop, you are not alloweded to use any other stack
int ReverseStack(struct SimpleStack *s){

    if(IsStackEmpty(s)){
       return ;
    }
    int data = Pop(s);
    ReverseStack(s);
    InsertAtBottom(s,data);
}
Ejemplo n.º 4
0
void main() {
    int length = 0;
    printf("Please input the length of array:\n");
	scanf("%d",&length);
	int stack[length];
	printf("Please input the array:\n");
	for(int i=0;i<length;i++){
	   scanf("%d",&stack[i]);
	}
	ReverseStack(stack,length - 1);
	for(int i=0;i<length;i++){
	   printf("%d ",stack[i]);
	}
}