graph_t *KCoreGraph::subgraph(IntStack *vset) { assert(!vset->empty()); graph_t *g = graph_new(maxsize()); IntStack *nb; int val,preval,val2,preval2; val = vset->head(); preval = val-1; while (val != preval) { nb = neighbourhoods.at(val); if (!nb->empty()) { val2 = nb->head(); preval2 = val2-1; while (val2 != preval2) { if ((val > val2) && vset->contain(val2)) GRAPH_ADD_EDGE(g,val,val2); preval2 = val2; val2 = nb->next(preval2); } } preval = val; val = vset->next(preval); } return g; };
ReversibleSet(Environment *s, const int lb=0, const int ub=0, const int sz=-1, const bool full=true) : Reversible(s) { if(sz < 0) initialise(lb, ub, ub-lb+1, full); else initialise(lb, ub, sz, full); }
virtual void initialise(Environment *s, const int lb, const int ub, const Vector<int>& vals) { Reversible::initialise(s); initialise(lb, ub, vals); // trail_.add(size); // trail_.add(-1); }
virtual void initialise(Environment *s, const int lb, const int ub, const int sz, const bool full) { Reversible::initialise(s); initialise(lb, ub, sz, full); // trail_.add(size); // trail_.add(-1); }
void KCoreGraph::remove_vertex(const int idvert) { assert(neighbourhoods.at(idvert) != NULL); /* Vertex to be removed */ IntStack *vn = neighbourhoods.at(idvert); /* Remove the edges between vn and its neighbors */ int val; while (!vn->empty()) { val = vn->head(); neighbourhoods.at(val)->remove(idvert); if (((int)(neighbourhoods.at(val)->size)) < k) { if (!tbr->contain(val)) tbr->add(val); } vn->remove(val); } /* Remove vn */ neighbourhoods.at(idvert) = NULL; delete(vn); };
int main(int, char **) { cout << "IntStack:" << endl; IntStack stack; cout << "Empty: " << stack.IsEmpty() << endl; stack.Push(10); cout << "Empty: " << stack.IsEmpty() << endl; int val = stack.Pop(); cout << "Popped off: " << val << endl; cout << "Empty: " << stack.IsEmpty() << endl; cout << "IntPtrStack:" << endl; IntPtrStack stack2; int value = 42; cout << "Empty: " << stack2.IsEmpty() << endl; stack2.Push(&value); cout << "Empty: " << stack2.IsEmpty() << endl; int *valptr = stack2.Pop(); cout << "Popped off: " << *valptr << endl; cout << "Empty: " << stack2.IsEmpty() << endl; return 0; }
int main() { IntStack intStack; intStack.push(1); intStack.push(2); intStack.push(3); while (!intStack.empty()) { int t = intStack.top(); intStack.pop(); printf("%d\n", t); } intStack.push(4); intStack.push(5); while (!intStack.empty()) { int t = intStack.top(); intStack.pop(); printf("%d\n", t); } return 0; }
int main() { IntStack stack; while(true) { string cmd; cin >> cmd; if(cmd == "push") { int elem; cin >> elem; stack.push(elem); } if(cmd == "pop") { stack.pop(); } if(cmd == "top") { cout << stack.top() << " is at the top" << endl; } cout << stack << endl; }
int main() { IntStack s; s.push(1); s.push(2); s.push(3); s.clear(); s.top(); s.pop(); return 0; }
int main() { IntStack s; s.push(1); s.push(2); s.pop(); s.push(3); s.pop(); s.push(4); return 0; }
int main() { IntStack stack; int curr; char oper; char tmp; int right, left; while(cin >> tmp) { if(isdigit(tmp)) { cin.putback(tmp); cin >> curr; stack.push(curr); } else { oper = tmp; right = stack.pop(); left = stack.pop(); switch (oper) { case '+': stack.push(left + right); break; case '-': stack.push(left - right); break; case '*': stack.push(left * right); break; } } }
int main(int argc, char** argv) { ifstream fileInput; fileInput.open(argv[1]); IntStack *stack = new IntStack(); int value; while (fileInput.peek() != EOF) { while ((fileInput.peek() != '\n') && (fileInput >> value)) { stack->push(value); } fileInput.get(); // chomp the newline while (!stack->isEmpty()) { cout << stack->pop() << " "; if (!stack->isEmpty()) { stack->pop(); } } cout << endl; } }
void initialise(Environment *s, const PRIMITIVE_TYPE v) { Reversible::initialise(s); initialise(v); }
ReversibleNum(const PRIMITIVE_TYPE v) { initialise(v); }