employer cover photo
employer logo
employer logo

Huawei Technologies

Is this your company?

Huawei Technologies Interview Question

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

Interview Answers

Anonymous

Dec 5, 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

Anonymous

Jul 7, 2012

try urself, I did it.