Pregunta de entrevista de Huawei Technologies

implement Stack by yourself, and reverse the content of it without using any extra memory space ?

Respuestas de entrevistas

Anónimo

5 dic 2013

public static void revertStack(Stack s) { if (s.isEmpty()) { return; } else { Integer a = s.pop(); revertStack(s); appendStack(s, a); } } public static void appendStack(Stack s, Integer a) { if (s.isEmpty()) { s.push(a); return; } else { Integer o = s.pop(); appendStack(s, a); s.push(o); } }

1

Anónimo

7 jul 2012

try urself, I did it.