Question d’entretien chez Huawei Technologies

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

Réponses aux questions d'entretien

Utilisateur anonyme

5 déc. 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

Utilisateur anonyme

7 juil. 2012

try urself, I did it.