Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
ESTOU COM DIFICULDADES EM INVERTER UMA PILHA EN JAVA,
A ASSINATURA DO MÉTODO DEVE SER
public Stack reverse() ,na seguinte classe Starck
package estruturas_sequenciais;
public class Stack {
private Object s[];
private Object d[];
private int top = -1;
public Stack(int size) {
s = new Object;
}
public boolean isEmpty() {
if (top == -1)
return true;
return false;
}
public boolean isFull() {
if (top == s.length - 1)
return true;
return false;
}
public void push(Object obj) throws OverflowException {
if (!isFull()) {
s[++top] = obj;
} else
throw new OverflowException();
}
public Object pop() throws UnderflowException {
if (!isEmpty()) {
Object o = s[top];
s[top] = null;
top--;
return o;
} else
throw new UnderflowException();
}
public void imprime()
{
for(int i = 0; i <= top; i ++)
System.out.print(s*);*
}
public Stack reverse()
throws UnderflowException, OverflowException
{
}
}
Consegui resolver o método Stack reverse que inverte os valores de uma pilha.
public Stack reverse()
throws UnderflowException, OverflowException
{
while(!aux.isEmpty()){
for(int i = 0; i <= top; i ++)
result.push(aux.pop());
}
return result;
}