implement Stack by yourself, and reverse the content of it without using any extra memory space ?
Utilisateur anonyme
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); } }