本文整理汇总了Java中java.util.Stack.pop方法的典型用法代码示例。如果您正苦于以下问题:Java Stack.pop方法的具体用法?Java Stack.pop怎么用?Java Stack.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Stack
的用法示例。
在下文中一共展示了Stack.pop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isBipartite
import java.util.Stack; //导入方法依赖的package包/类
/**
* Returns whether the given graph is bipartite.
*
* @param graph
* to be checked if it is bipartite
* @return whether the given graph is bipartite
*/
public static boolean isBipartite(Graph graph) {
if (graph.getN() == 0)
return true;
int[] partition = new int[graph.getN()];
Arrays.fill(partition, -1);
Stack<Vertex> stack = new Stack<Vertex>();
stack.add(graph.getVertexById(0));
partition[0] = 0;
while (!stack.empty()) {
Vertex u = stack.pop();
for (Vertex v : u.getNeighbors()) {
if (partition[v.getId()] == partition[u.getId()])
return false;
if (partition[v.getId()] == -1) {
partition[v.getId()] = 1 - partition[u.getId()];
stack.add(v);
}
}
}
return true;
}
示例2: forEachBlockDepthFirstDom
import java.util.Stack; //导入方法依赖的package包/类
/**
* Visits blocks in dom-tree order, starting at the current node.
* The {@code parent} parameter of the Visitor.visitBlock callback
* is currently always set to null.
*
* @param v {@code non-null;} callback interface
*/
public void forEachBlockDepthFirstDom(SsaBasicBlock.Visitor v) {
BitSet visited = new BitSet(getBlocks().size());
Stack<SsaBasicBlock> stack = new Stack<SsaBasicBlock>();
stack.add(getEntryBlock());
while (stack.size() > 0) {
SsaBasicBlock cur = stack.pop();
ArrayList<SsaBasicBlock> curDomChildren = cur.getDomChildren();
if (!visited.get(cur.getIndex())) {
// We walk the tree this way for historical reasons...
for (int i = curDomChildren.size() - 1; i >= 0; i--) {
SsaBasicBlock child = curDomChildren.get(i);
stack.add(child);
}
visited.set(cur.getIndex());
v.visitBlock(cur, null);
}
}
}
示例3: toTree
import java.util.Stack; //导入方法依赖的package包/类
private final void toTree(Stack<Pair<Integer,Boolean>> indent, StringBuilder result) {
if (getArgs().size() > 0) {
String symbol = getOp().getSymbol();
result.append(symbol);
result.append(getArgs().size() == 1 ? " --- " : " +-- ");
int i;
for (i = 0; i < getArgs().size() - 1; i++) {
indent.push(Pair.newPair(symbol.length(), true));
getUpArg(i).toTree(indent, result);
result.append('\n');
addIndent(indent, result);
indent.pop();
}
indent.push(Pair.newPair(symbol.length(), false));
getUpArg(i).toTree(indent, result);
indent.pop();
} else if (getOp().getKind() == OpKind.ATOM) {
result.append(toAtomString());
}
}
示例4: findEncryptedParts
import java.util.Stack; //导入方法依赖的package包/类
public static List<Part> findEncryptedParts(Part startPart) {
List<Part> encryptedParts = new ArrayList<>();
Stack<Part> partsToCheck = new Stack<>();
partsToCheck.push(startPart);
while (!partsToCheck.isEmpty()) {
Part part = partsToCheck.pop();
Body body = part.getBody();
if (isPartMultipartEncrypted(part)) {
encryptedParts.add(part);
continue;
}
if (body instanceof Multipart) {
Multipart multipart = (Multipart) body;
for (int i = multipart.getCount() - 1; i >= 0; i--) {
BodyPart bodyPart = multipart.getBodyPart(i);
partsToCheck.push(bodyPart);
}
}
}
return encryptedParts;
}
示例5: reduce
import java.util.Stack; //导入方法依赖的package包/类
private static Token reduce(Stack<Token> st, JobConf job) throws IOException {
LinkedList<Token> args = new LinkedList<Token>();
while (!st.isEmpty() && !TType.LPAREN.equals(st.peek().getType())) {
args.addFirst(st.pop());
}
if (st.isEmpty()) {
throw new IOException("Unmatched ')'");
}
st.pop();
if (st.isEmpty() || !TType.IDENT.equals(st.peek().getType())) {
throw new IOException("Identifier expected");
}
Node n = Node.forIdent(st.pop().getStr());
n.parse(args, job);
return new NodeToken(n);
}
示例6: getVisibleNodesD
import java.util.Stack; //导入方法依赖的package包/类
/**
* DFS use <code>Stack</code>
*/
public static ArrayList<DefaultTreeNode> getVisibleNodesD(DefaultTreeNode aRoot) {
ArrayList<DefaultTreeNode> list = new ArrayList<>();
Stack<DefaultTreeNode> stack = new Stack<>();
if (aRoot == null) {
return null;
}
stack.push(aRoot);
while (!stack.isEmpty()) {
DefaultTreeNode node = stack.pop();
list.add(node);
LinkedList<DefaultTreeNode> children = node.getChildren();
if (children == null) {
continue;
}
//add children in reversed order
for (int i = children.size() - 1; i >= 0; i--) {
if (node.isExpanded()) {
stack.push(children.get(i));
}
}
}
return list;
}
示例7: isConnected
import java.util.Stack; //导入方法依赖的package包/类
public boolean isConnected() {
if (this.getNumVertices() == 0) {
return true;
}
Vertex[] vertices = this.getVertices();
Stack<Vertex> toVisit = new Stack<Vertex>();
toVisit.add(vertices[0]);
Set<Vertex> visited = new HashSet<Vertex>();
while (!toVisit.isEmpty()) {
Vertex v = toVisit.pop();
visited.add(v);
Vertex[] next = this.getNeighbours(v);
for (Vertex n : next) {
if (!visited.contains(n)) {
toVisit.add(n);
}
}
}
return visited.size() == vertices.length;
}
示例8: getButtons
import java.util.Stack; //导入方法依赖的package包/类
/**
* Gets the buttons attribute of the FileChooserFixer object
*
* @param fc Description of the Parameter
* @return The buttons value
*/
protected JButton[] getButtons(JFileChooser fc) {
Vector<Component> v = new Vector<>();
Stack<Component> s = new Stack<>();
s.push(fc);
while (!s.isEmpty()) {
Component c = s.pop();
if (c instanceof Container) {
Container d = (Container) c;
for (int i = 0; i < d.getComponentCount(); i++) {
if (d.getComponent(i) instanceof JButton) {
v.add(d.getComponent(i));
} else {
s.push(d.getComponent(i));
}
}
}
}
JButton[] arr = new JButton[v.size()];
for (int i = 0; i < arr.length; i++) {
arr[i] = (JButton) v.get(i);
}
return arr;
}
示例9: execute
import java.util.Stack; //导入方法依赖的package包/类
/**
* Execute the instruction.
*
* @param frame The currently executed frame.
* @throws ExecutionException Thrown in case of fatal problems during the execution.
*/
@Override
public void execute(Frame frame) throws ExecutionException {
try {
// Get the dimensions and their length.
int dimensions = this.otherBytes[2];
int[] count = new int[dimensions];
Stack<Object> stack = frame.getOperandStack();
for (int a = dimensions - 1; a >= 0; a--) {
count[a] = (Integer) stack.pop();
// Runtime Exception: count is less than zero.
if (count[a] < 0)
throw new VmRuntimeException(frame.getVm().generateExc("java.lang.NegativeArraySizeException",
"Cannot create an array of negative size."));
}
// Create the array.
generateAndPushNewArray(frame, count);
} catch (VmRuntimeException e) {
ExceptionHandler handler = new ExceptionHandler(frame, e);
try {
handler.handleException();
} catch (ExecutionException e2) {
executionFailed(e2);
}
}
}
示例10: execute
import java.util.Stack; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void execute(Stack<Object> stack, RequestContext request) {
String name = (String) stack.pop();
Object value = stack.pop();
request.setTemporaryParameter(name, value.toString());
}
示例11: isValid
import java.util.Stack; //导入方法依赖的package包/类
public boolean isValid(String s){
int length = s.length();
int i = 0;
Stack<Character> stack = new Stack<>();
while(i < length){
if(s.charAt(i) == '(' || s.charAt(i) == '[' || s.charAt(i) == '{'){
stack.push(s.charAt(i));
i++;
continue;
}
if(s.charAt(i) == ')' && !stack.empty() && stack.peek() == '('){
stack.pop();
i++;
continue;
}else{
stack.push(s.charAt(i));
}
if(s.charAt(i) == ']' && !stack.empty() && stack.peek() == '['){
stack.pop();
i++;
continue;
}else{
stack.push(s.charAt(i));
}
if(s.charAt(i) == '}' && !stack.empty() && stack.peek() == '{'){
stack.pop();
i++;
continue;
}else{
stack.push(s.charAt(i));
}
i++;
continue;
}
return stack.empty();
}
示例12: combine
import java.util.Stack; //导入方法依赖的package包/类
/**
*
* @param exps
*/
public static AbstractExpression combine(List<AbstractExpression> exps) {
Stack<AbstractExpression> stack = new Stack<AbstractExpression>();
stack.addAll(exps);
if (stack.isEmpty()) {
return null;
} else if (stack.size() == 1) {
return stack.pop();
}
AbstractExpression ret = null;
while (stack.size() > 1) {
AbstractExpression child_exp = stack.pop();
//
// If our return node is null, then we need to make a new one
//
if (ret == null) {
ret = new ConjunctionExpression(ExpressionType.CONJUNCTION_AND);
ret.setLeft(child_exp);
//
// Check whether we can add it to the right side
//
} else if (ret.getRight() == null) {
ret.setRight(child_exp);
stack.push(ret);
ret = null;
}
}
if (ret == null) {
ret = stack.pop();
} else {
ret.setRight(stack.pop());
}
return ret;
}
示例13: executeSymbolically
import java.util.Stack; //导入方法依赖的package包/类
/**
* Execute the instruction symbolically.
* @param frame The currently executed frame.
*/
@Override
public void executeSymbolically(Frame frame) {
Stack<Object> stack = frame.getOperandStack();
Term oldTerm = (Term) stack.pop();
Term newTerm = TypeCast.newInstance(oldTerm, oldTerm.getType(), Expression.INT);
stack.push(newTerm);
}
示例14: disengageThread
import java.util.Stack; //导入方法依赖的package包/类
/**
* Unset the current ExecutionContext
* @see #engageThread(ServletConfig, HttpServletRequest, HttpServletResponse)
*/
public static void disengageThread() {
if (contextStack != null) {
Stack<WebContext> stack = contextStack.get();
if (stack != null) {
if (!stack.empty()) {
stack.pop();
}
if (stack.empty()) {
contextStack.set(null);
}
}
}
}
示例15: executeSymbolically
import java.util.Stack; //导入方法依赖的package包/类
/**
* Execute the instruction symbolically.
* @param frame The currently executed frame.
* @throws SymbolicExecutionException Thrown in case of fatal problems during the symbolic execution.
*/
@Override
public void executeSymbolically(Frame frame) throws SymbolicExecutionException {
try {
Stack<Object> stack = frame.getOperandStack();
Object value1 = stack.pop();
Object value2 = stack.pop();
if (!checkCategory2(value1) && checkCategory2(value2)) {
// Form 2: value1 is a type of category 1, while value2 is a type of category 2.
stack.push(value2);
stack.push(value1);
} else {
Object value3 = stack.pop();
if (!(checkCategory2(value1) || checkCategory2(value2) || checkCategory2(value3))) {
// Form 1: All three values are types of category 1.
stack.push(value1);
stack.push(value3);
stack.push(value2);
stack.push(value1);
} else {
// Recovery.
stack.push(value3);
stack.push(value2);
stack.push(value1);
throw new ExecutionException("When using " + getName() + " either the three topmost values of the operand stack must not be category 2 types, or the topmost value must be a category 1 type, while the second one must be a category 2 type.");
}
}
} catch (ExecutionException e) {
symbolicExecutionFailedWithAnExecutionException(e);
}
}