You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think there are some mistakes in sort_stack's pseudocode and test cases description.
The test cases section says:
Empty stack -> None
But it should be returning an empty stack, not None.
Under the algorithm section, it says
" * While buffer is not empty or buffer top is > than temp\n",
but the code says
whilenotbuff.is_empty() andtemp<buff.peek():
so that should be an and, not an or.
It also says
"* Our buffer will hold elements in reverse sorted order, smallest at the top\n",
but the buffer stores elements in sorted order, largest at the top. Otherwise, how could we return buffer as our answer when the output should have the largest element at the top?
I also suggest changing
"* Store the current top element in a temp variable\n",
to
" * Pop the current top element of stack into a temp variable\n",
This clarifies that the top element is not just copied to a temp variable, but rather popped off into the temp variable. Also this happens within the outer while loop, not before.
Here's the code version of the solution for reference:
I think there are some mistakes in sort_stack's pseudocode and test cases description.
The test cases section says:
But it should be returning an empty stack, not None.
Under the algorithm section, it says
but the code says
so that should be an and, not an or.
It also says
but the buffer stores elements in sorted order, largest at the top. Otherwise, how could we return buffer as our answer when the output should have the largest element at the top?
I also suggest changing
to
This clarifies that the top element is not just copied to a temp variable, but rather popped off into the temp variable. Also this happens within the outer while loop, not before.
Here's the code version of the solution for reference:
I've submitted pull request #263 for this issue.
The text was updated successfully, but these errors were encountered: