Explain how to implement two stacks in one array A[1..n] in such a way that neither stack overflows unless the total number elements in both stacks together exceeds n. Show your work for the new PUSH,POP operations

Respuesta :

Answer:

Check explanation

Explanation:

Two stacks can make use of one array by utilizing various stack pointers that begins from different ends of an array. Looking at the array A[1...[tex]n[/tex]], the first stack will drive elements that starts from position 1 as well as to move its' pointer to [tex]n[/tex].

The Second stack will begin at the [tex]n[/tex] position and motion its' pointer to 1. The best likely divide is to offer each stack a half of an array. whenever any of two stacks transverse the half-point, an overflow can happen but for that overall number of elements, it must be [tex]n[/tex]