answersLogoWhite

0

public void reverse(Stack st)

{

int m = (int)st.Pop();

if (st.Count != 1)

reverse(st);

Push(st , m);

}

public void Push(Stack st , int a)

{

int m = (int)st.Pop();

if (st.Count != 0)

Push(st , a);

else

st.Push(a);

st.Push(m);

}

User Avatar

Wiki User

17y ago

What else can I help you with?

Related Questions

Can you implement merge sort without using recursion?

Sure, recursion can always be substituted with using a stack.


Is Recursion operation of the stack?

yes


Can you provide a solution to the diamond-square algorithm using Java and recursion?

Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.


C program to implement tower of hanoi using array implementation of stack abstract datatype?

stack abstract datatype


What is the use of recursion function?

Read the part in your programming manual/text book about recursion. The short answer while easy does not tell you anything about the power or dangers of recursion. It is the power and dangers of recursion that is important because once understood you can use recursion to good effect without running out of stack space.


What are the differences between tail recursion and recursion, and how do they impact the efficiency and performance of algorithms?

Tail recursion is a special type of recursion where the recursive call is the last operation in the function. This allows for optimization by reusing the same stack frame for each recursive call, leading to better efficiency and performance. In contrast, regular recursion may require storing multiple stack frames, which can lead to higher memory usage and potentially slower execution.


Is there any way to perform quick sort other than stack?

Stack is not a way to perform quicksort, it is a tool used to implement recursion.


What is funcation?

Read the part in your programming manual/text book about recursion. The short answer while easy does not tell you anything about the power or dangers of recursion. It is the power and dangers of recursion that is important because once understood you can use recursion to good effect without running out of stack space.


How can you implement a queue using stacks efficiently?

To implement a queue using stacks efficiently, you can use two stacks. One stack is used for enqueueing elements, and the other stack is used for dequeueing elements. When dequeueing, if the dequeue stack is empty, you can transfer elements from the enqueue stack to the dequeue stack to maintain the order of elements. This approach allows for efficient implementation of a queue using stacks.


Can heap implement recursion?

Heap is a data-structure, it cannot implement anything. On the other hand, it is true that: 1. Recursive routines might use heap. 2. You can use dynamic memory allocation (heap), to implement a stack; and use the stack to implement recursion.


Is cursor implementation possible in queue or stack?

yes,cursor implementation possible in priority queue.


How do you overcome limitations of stacks in polygon filling?

You overcome limitations of the stack in polygon filling, or in any other algorithm, far that matter, but using an iterative technique, rather than a recursive technique. Recursion is quite useful, and can simplify algorithm design. Polygon filling, however, is a class of algorithm can potentially have a very deep recursion depth. This causes stress on the stack, hence the need for iteration.