예제 #1
0
void reverse(Stack **top) 
{
    if(!isEmpty(top))
    {
        int temp = pop(top);
        reverse(top);
        insertAtBottom(top,temp);
    }
}
예제 #2
0
파일: AStack.c 프로젝트: RAJU009F/my-work
void reverseStack(struct Stack *s)
			{
				if(isEmpty(s))
					return;
				int data = pop(s);
				reverseStack(s);
				insertAtBottom(s, data);		
			
			
			}
예제 #3
0
void insertAtBottom(Stack **top, int x)
{
    if(isEmpty(top)){
        push(top,x);
    } else {
        int item = pop(top);
        insertAtBottom(top, x);
        push(top,item);
    }
}
예제 #4
0
void reverse(struct sNode ** top_ref)
{
  if(!isEmpty(*top_ref))
  {
    int temp = pop(top_ref);
    reverse(top_ref);

    insertAtBottom(top_ref,temp);

  }

}
예제 #5
0
파일: AStack.c 프로젝트: RAJU009F/my-work
void insertAtBottom(struct Stack *s, int data)
				{
					if (isEmpty(s))
						{
							push(s, data);
							return;
						}
					int ele = pop(s);
					insertAtBottom(s, data);
					push(s,ele);
				
				
				}
예제 #6
0
// Reverse the given stack using insertAtBottom
void reverse(struct sNode** top_ref)
{
    if (!isEmpty(*top_ref))
    {
        /* Hold all items in function call stack until we
           reach end of the stack
        */
        int temp = pop(top_ref);
        reverse(top_ref);

        /* Insert all the items (held in function call stack)
           one by one from the bottom to top. Every item is
           inserted at the bottom*/
        insertAtBottom(top_ref, temp);
    }
}
예제 #7
0
void insertAtBottom(struct sNode ** top_ref,int item)
{

  if(isEmpty(*top_ref))
  {
    push(top_ref,item);

  }
  else {

      int temp = pop(top_ref);
      insertAtBottom(top_ref,item);

      push(top_ref,temp);


  }

}
예제 #8
0
// Recursive function that inserts an element 
// at the bottom of a stack
void insertAtBottom(struct sNode** top_ref, int item)
{
    if (isEmpty(*top_ref))
        push(top_ref, item);
    else
    {
        /*
        Hold all items in function call stack until we reach
        end of the stack. when the stack becomes empty, 
        the isEmpty(*top_ref) becomes true, the above if part is
        executed and the item is inserted at the bottom
        */
        int temp = pop(top_ref);
        insertAtBottom(top_ref, item);

        /*
        Once the item is inserted at the bottom, push all the items
        held in function call stack
        */
        push(top_ref, temp);
    }
}