b**a 发帖数: 1118 | 1 Design an efficient algorithm to sort elements in a stack in either
ascending/descending order, using only pop(), top(), push(), isEmpty(),
isFull(). Do not use any auxiliary stacks or arrays.
I found this question in jobhunting board. the anwser given by a niu ren is
Is this right? Does not look like right one.Thanks. | c*****t 发帖数: 1879 | 2 You didn't post the complete code. What you looked at was mostly a
for-loop.
is
【在 b**a 的大作中提到】 : Design an efficient algorithm to sort elements in a stack in either : ascending/descending order, using only pop(), top(), push(), isEmpty(), : isFull(). Do not use any auxiliary stacks or arrays. : I found this question in jobhunting board. the anwser given by a niu ren is : Is this right? Does not look like right one.Thanks.
| E*V 发帖数: 17544 | 3 seems right
why dont' you test it?
is
【在 b**a 的大作中提到】 : Design an efficient algorithm to sort elements in a stack in either : ascending/descending order, using only pop(), top(), push(), isEmpty(), : isFull(). Do not use any auxiliary stacks or arrays. : I found this question in jobhunting board. the anwser given by a niu ren is : Is this right? Does not look like right one.Thanks.
| w***g 发帖数: 5958 | 4 This is a recursive algorithm, and it actually uses an auxiliary stack
, though not obvious to newbies. This is actually more dangerous than
explicitly using some auxiliary data structure because recursion may lead to
stack overflow.
is
【在 b**a 的大作中提到】 : Design an efficient algorithm to sort elements in a stack in either : ascending/descending order, using only pop(), top(), push(), isEmpty(), : isFull(). Do not use any auxiliary stacks or arrays. : I found this question in jobhunting board. the anwser given by a niu ren is : Is this right? Does not look like right one.Thanks.
|
|