Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
A stack is a last in, first out (LIFO) abstract data type and data structure. Perhaps the most common use of stacks is to store subroutine arguments and return addresses.
0
votes
Stack with 'getMinimum' operation
As others have noted, Stack extends Vector. As such Stack is a List. … As such, you can probably not get around using Stack for this exercise, but note that Stack, as a subclass of Vector, carries synchronized overhead, which in most cases you won't need. …
5
votes
Check for balanced parentheses
I've only one addition to the other answers
For the stack you use java.util.Stack, this seems like an obvious choice, yet it is a remnant from pre-collection times, and is a subclass of java.util.Vector … That is a double ended queue, but functions perfectly as a stack if only accessed from the top. In fact Stack's javadoc advises you to use ArrayDeque instead. …
2
votes
Accepted
Mergesorting a stack in Java
super E>> void sort(final Stack<E> stack) {
if (stack.size() < 2) {
// Trivially sorted. … return;
}
if (stack.size() == 2) {
sortSize2Stack(stack);
return;
}
sortLargerStack(stack);
}
For the size two stack case you can avoid popping the second element if …