/* Driver program to test twStacks class */ int main() { struct TwoStack * twoStacks = createStacks(5); push1(twoStacks, 5); push2(twoStacks, 10); push2(twoStacks, 15); push1(twoStacks, 11); push2(twoStacks, 7); printf("Popped element from stack1 is %d", pop1(twoStacks)); push2(twoStacks, 40); printf("\nPopped element from stack2 is %d", pop2(twoStacks)); return 0; }
int main(){ struct doublestack dstack; dstack.topFirstStack =-1; dstack.topSecondStack =100; push1(&dstack,10); push1(&dstack,20); push2(&dstack,30); push2(&dstack,50); int x = pop1(&dstack); printf("Pop item from stack one %d \n",x); int y = pop2(&dstack); printf("Pop item from stack two %d \n",y); }
int main() { size = 5; top1= -1; top2 = 5; push1(5); push2(10); push1(45); push1(12); push2(41); printf("Element Popped from stack 1 is: %d\n",pop1()); printf("Element Popped from stack 2 is: %d\n",pop2()); return 0; }
int main(void) { char buf[1024] = ""; char *p = NULL; fgets(buf,sizeof(buf),stdin); p = strtok(buf," \n"); push2(atoi(p)); while((p = strtok(NULL, " \n")) != NULL) { char op; int b, a; switch(*p) { case '+': case '-': //if(!is_empty()) { while (top1 != 0) { op = pop1(); //if(*op == ' ') // break; b = pop2(); a = pop2(); if(op == '+') push2(a + b); else push2(a - b); }; } push1(*p); break; case '*': case '/': push1(*p); break; default: push2(atoi(p)); } } switch(pop1()){ case '+': printf("%d\n",pop2() + pop2());break; case '-': printf("%d\n",pop2() - pop2());break; case '*': printf("%d\n",pop2() * pop2());break; case '/': printf("%d\n",pop2() / pop2());break; } //printf("%d\n",pop2()); destory(); return 0; }
int main() { boost::thread pop_sync1(&popper_sync); boost::thread pop_sync2(&popper_sync); boost::thread pop_sync3(&popper_sync); boost::thread push1(&pusher); boost::thread push2(&pusher); boost::thread push3(&pusher); // Waiting for all the tasks to push push1.join(); push2.join(); push3.join(); g_queue.flush(); // Waiting for all the tasks to pop pop_sync1.join(); pop_sync2.join(); pop_sync3.join(); // Asserting that no tasks remained, // and falling though without blocking assert(!g_queue.try_pop_task()); g_queue.push_task(&do_nothing); // Asserting that there is a task, // and falling though without blocking assert(g_queue.try_pop_task()); }
int main() { int choice, item; do { printf("Press\n[1] To insert\n[2] To delete\n[3] To display\n[4] To exit\nEnter choice: "); scanf("%d",&choice); switch(choice) { case 1: printf("Enter the number to insert: "); scanf("%d",&item); push1(item); pop1(); break; case 2: pop2(); break; case 3: printf("The content of queue is: \n"); display(); break; case 4: exit(0); default: printf("Invalid Entry!"); } }while(1); }
/*Function to add an element into the queue using stack*/ void enqueue() { int data, i; printf("Enter data into queue"); *(&data)=542; push1(data); count++; }
int result(char fir[],int plus) //算出结果 { char c,ch; int x,y,i = 0; count1 = 0; count2 = 0; push2('#'); while( fir[i]!='#' || optr[count2-1]!='#') { c = fir[i]; if( isdigit(c) ) { push1(c-'0'); i++; continue; } if( isalpha(c) ) { push1(c-'a'+plus); i++; continue; } if(c == '+' || c== '-'||c=='*' || c=='('||c==')'||c=='#') { switch( record(optr[count2-1],c) ) { case -1: push2(c); i++; break; case 0 : pop2(); i++; break; case 1 : ch = pop2(); y = pop1(); x = pop1(); push1(computer(x,y,ch)); break; } } else i++; } return opnd[count1-1]; }
// This adds a-1 empty cells, then b+1 cells with a top_border void Stack::add_border(int a, int b) { push1(np_row); push_pop_cell(push_only); for(int i=1;i<a;i++) push_pop_cell(push_and_pop); for(int i=0;i<b;i++) { add_att_to_last(np_topborder,np_true); push_pop_cell(push_and_pop); } add_att_to_last(np_topborder,np_true); push_pop_cell(pop_only); pop(np_row); }
void dequeue() { int i; for (i = 0;i <= count;i++) { push2(pop1()); } pop2(); count--; for (i = 0;i <= count;i++) { push1(pop2()); } }
void main() { int a[10],b[10],n,m,i; scanf("%d %d",&n,&m); for(i=0;i<n;i++) { scanf("%d",&a[i]); push(a[i]); } for(i=0;i<m;i++) { scanf("%d",&b[i]); push1(b[i]); } merge(); getch(); }
int main() { int choice, num, exit = 0; while(exit != 1){ printf("1. Input to stack-1\n" "2. Input to stack-2\n" "3. POP from stack-1\n" "4. POO from stack-2\n" "5. Print Stacks\n" "6. Exit\n"); scanf("%d", &choice); switch(choice){ case 1: printf("Input a number to add to the stack\n"); scanf("%d", &num); push1(num); break; case 2: printf("Input a number to add to the stack\n"); scanf("%d", &num); push2(num); break; case 3: pop1(); break; case 4: pop2(); break; case 5: print(); break; case 6: exit = 1; break; default: printf("Not a valid choice, Try Again!!\n"); break; } } }
Calculator::Calculator(QWidget *parent) : QWidget(parent), ui(new Ui::Calculator) { ui->setupUi(this); pastNumber = 0; currentNumber = ui->lcd->value(); state = '\0'; point = false; in = false; count = 0; connect(ui->button0, SIGNAL(clicked()), this, SLOT(push0())); connect(ui->button1, SIGNAL(clicked()), this, SLOT(push1())); connect(ui->button2, SIGNAL(clicked()), this, SLOT(push2())); connect(ui->button3, SIGNAL(clicked()), this, SLOT(push3())); connect(ui->button4, SIGNAL(clicked()), this, SLOT(push4())); connect(ui->button5, SIGNAL(clicked()), this, SLOT(push5())); connect(ui->button6, SIGNAL(clicked()), this, SLOT(push6())); connect(ui->button7, SIGNAL(clicked()), this, SLOT(push7())); connect(ui->button8, SIGNAL(clicked()), this, SLOT(push8())); connect(ui->button9, SIGNAL(clicked()), this, SLOT(push9())); connect(ui->buttonDot, SIGNAL(clicked()), this, SLOT(pushpoint())); connect(ui->buttonCE, SIGNAL(clicked()), this, SLOT(ce())); connect(ui->buttonC, SIGNAL(clicked()), this, SLOT(c())); connect(ui->buttonPlus, SIGNAL(clicked()), this, SLOT(pushPlus())); connect(ui->buttonSub, SIGNAL(clicked()), this, SLOT(pushSub())); connect(ui->buttonTimes, SIGNAL(clicked()), this, SLOT(pushTimes())); connect(ui->buttonDiv, SIGNAL(clicked()), this, SLOT(pushDiv())); connect(ui->buttonEqual, SIGNAL(clicked()), this, SLOT(pushEqual())); QFont font = ui->button0->font(); font.setPointSize(40); ui->button0->setFont(font); ui->button1->setFont(font); ui->button2->setFont(font); ui->button3->setFont(font); ui->button4->setFont(font); ui->button5->setFont(font); ui->button6->setFont(font); ui->button7->setFont(font); ui->button8->setFont(font); ui->button9->setFont(font); ui->buttonC->setFont(font); ui->buttonCE->setFont(font); ui->buttonEqual->setFont(font); ui->buttonDiv->setFont(font); ui->buttonTimes->setFont(font); ui->buttonPlus->setFont(font); ui->buttonSub->setFont(font); ui->buttonDot->setFont(font); }
double eval(stack * stk, stack1 * no) { stack1 nos = NULL; double x, y, z; char ch; ldiv_t ldivt; while (!empty(*stk)) { *stk = pop(*stk, &ch); if (ch == 'N') { *no = pop1(*no, &x); nos = push1(nos, x); } else if (ch == (char)0xD8) { } else { nos = pop1(nos, &y); if ((ch >= (char)0xA2 && ch <= (char)0xCA) && ch != (char)0xAA && ch != (char)0xCB && ch != (char)0xB9) x = 0; else nos = pop1(nos, &x); switch (ch) { case '+': z = add(x, y); break; case '-': z = dif(x, y); break; case '*': z = mul(x, y); break; case '/': if (y == 0.0) { eqp_errno = 6; return (0); } z = divide(x, y); break; case '^': z = pow(x, y); break; case '%': z = mod(x, y); break; /* The inline comments give the equivalent * gnuplot function */ case (char)0xA2: /* abs(x) */ z = fabs(y); break; case (char)0xA3: /* acos(x) */ if (y > 1 || y < -1) { /* eqp_errno = 9 ; return(0); */ } z = acos(y); break; case (char)0xA4: /* acosh(x) */ z = acosh(y); break; case (char)0xA6: /* asin(x) */ if (y > 1 || y < -1) { /* eqp_errno = 10 ; return(0); */ } z = asin(y); break; case (char)0xA7: /* asinh(x) */ z = asinh(y); break; case (char)0xA8: /* atan(x) */ z = atan(y); break; case (char)0xA9: /* atanh(x) */ if (y > 1 || y < -1) { eqp_errno = 11; return (0); } z = atanh(y); break; case (char)0xAA: /* atan2(y,x) */ z = atan2(x, y); break; case (char)0xAB: /* besj0(x) */ z = j0(y); break; case (char)0xAC: /* besj1(x) */ z = j1(y); break; case (char)0xAD: /* besy0(x) */ if (y <= 0) { eqp_errno = 8; return (0); } z = y0(y); break; case (char)0xAE: /* besy1(x) */ if (y <= 0) { eqp_errno = 18; return (0); } z = y1(y); break; case (char)0xAF: /* ceil(x) */ z = ceil(y); break; case (char)0xB1: /* cos(x) */ z = cos(y); break; case (char)0xB2: /* cosh(x) */ z = cosh(y); break; case (char)0xCB: /* div(num,denom) */ ldivt = ldiv((int) x, (int) y); z = (double) ldivt.quot; break; case (char)0xB3: /* erf(x) */ z = erf(y); break; case (char)0xB4: /* erfc(x) */ z = erfc(y); break; case (char)0xB5: /* exp(x) */ z = exp(y); break; case (char)0xB6: /* floor(x) */ z = floor(y); break; case (char)0xB7: /* gamma(x) */ z = exp(lgamma(y)); break; case (char)0xBB: /* int(x) */ z = rint(y); if (z > 0 && z > y) z--; if (z < 0 && z < y) z++; break; case (char)0xBC: /* inverf(x) */ if (y <= -1 || y >= 1) { eqp_errno = 19; return (0); } z = inverf(y); break; case (char)0xBD: /* invnorm(x) */ if (y <= 0 || y >= 1) { eqp_errno = 16; return (0); } z = sqrt(2) * inverf(2 * y - 1); break; case (char)0xBE: /* lgamma(x) */ z = lgamma(y); break; case (char)0xBF: /* log(x) */ if (y <= 0) { eqp_errno = 21; return (0); } z = log(y); break; case (char)0xC0: /* log10(x) */ z = log10(y); if (y <= 0) { eqp_errno = 20; return (0); } break; case (char)0xC1: /* norm(x) */ z = .5 * (1 + erf(y / sqrt(2))); break; case (char)0xC2: /* rand(x) */ z = ((double) rand()) / RAND_MAX; break; case (char)0xC4: /* sgn(x) */ if (y > 0) z = 1; else if (y < 0) z = -1; else z = 0; break; case (char)0xC5: /* sin(x) */ z = sin(y); break; case (char)0xC6: /* sinh(x) */ z = sinh(y); break; case (char)0xC7: /* sqrt(x) */ z = sqrt(y); break; case (char)0xC8: /* tan(x) */ z = tan(y); break; case (char)0xC9: /* tanh(x) */ z = tanh(y); break; } nos = push1(nos, z); } } nos = pop1(nos, &z); #ifdef DEBUG printf("\n%lf", z); #endif return (z); }
static int eval1(uint8_t a, uint8_t len) { err = ERR_OK; int tos = 0; sp = stack + STACK_SIZE; uint8_t a1 = a + len; while (a < a1) { uint8_t c = get(a++); uint8_t bcGroup = c & (~(MAX_QUICK - 1)); if (bcGroup == LIT_MASK) { int n = c & (MAX_QUICK - 1); push1(tos); tos = n - MAX_QUICK / 2; } else if (bcGroup == REG_MASK) { int n = c & (MAX_QUICK - 1); int val = 0; char b = getReg(n, &val); if (!b) err = ERR_WRONG_REGISTER; push1(tos); tos = val; } else { switch (c) { case LIT: { int s = get16(a); a += 2; push1(tos); tos = s; break; } case REG: { int s = get16(a); a += 2; int val = 0; char b = getReg(s, &val); if (!b) err = ERR_WRONG_REGISTER; push1(tos); tos = val; break; } case COND: { uint8_t n = get(a++); int n1 = tos; tos = pop1(); if (!n1) a += n; break; } case COND1: { uint8_t n = get(a++); a += n + 1; break; } case EQ: tos = tos == pop1(); break; case NEQ: tos = tos != pop1(); break; case LT: tos = pop1() < tos; break; case LE: tos = pop1() <= tos; break; case GT: tos = pop1() > tos; break; case GE: tos = pop1() >= tos; break; case PLUS: tos = pop1() + tos; break; case MINUS: tos = pop1() - tos; break; case MUL: tos = pop1() * tos; break; case DIV: tos = pop1() / tos; break; case NOT: tos = !tos; break; case NEG: tos = -tos; break; case OR: { uint8_t n = get(a++); tos = tos != 0; if (tos) a += n; else tos = pop1(); break; } case AND: { uint8_t n = get(a++); if (!tos) a += n; else tos = pop1(); break; } case NE0: tos = tos != 0; break; case PAR: break; default: err = ERR_UNKNOWN_BYTECODE; return 0; } } if (err != ERR_OK) return 0; } int n = tos; tos = pop1(); if (err != ERR_OK) return 0; if (sp != stack + STACK_SIZE) err = ERR_STACK_BALANCE; return n; }
// This starts or ends a cell, or does both void Stack::push_pop_cell(int dir) { if(dir != push_only) { pop(np_cell); add_nl(); } if(dir != pop_only) { push1(np_cell); } }
int main(){ int m , n ; int v1 , v2; int i; int count = 0; int mark; node *p; scanf ("%d%d",&n,&m); for( i = 1; i <= m ; i ++) { scanf("%d%d",&v1,&v2); add(v1,v2); } for( i = 1; i<= n ; i ++) { if(root[i].in == 0) { push(i); root[i].in = -1; } } /* for( i = 1; i <= n ;i ++) { printf("\n%d",i); p = root[i].next; while(p) { printf("->%d",p->num); p = p->next; } }*/ while(!empty()) { count++; while(!empty()) { mark = pop(); if( root[mark].next) { p = root[mark].next; root[p->num].in--; if(root[p->num].in == 0) { push1(p->num); } p = p->next; } while(p) { root[p->num].in--; if(root[p->num].in == 0) push1(p->num); p = p->next; } } /*for(i = 1; i <= n ; i ++) { if(root[i].in == 0) { push(i); root[i].in = -1; } }*/ if(empty1()) break; while(!empty1()) { push(pop1()); } } printf("%d",count ); /* for( i = 1 ; i <= n ;i ++) { printf("%d %d %d\n",i,root[i].in,root[i].out); } */ return 0; }
int main() { int i,j,k,pos,xtmp,ytmp,source,sink,curVer; FILE *fin = fopen ("project1.in", "r"); fscanf(fin,"%d %d",&verSum,&edgSum); for(i=0;i<verSum;i++) { fscanf(fin,"%d %d %d",&pos,&xtmp,&ytmp); vertices[pos].pos=(xtmp<<16)|ytmp; vertices[pos].is=1; } for(i=0;i<edgSum;i++) { fscanf(fin,"%d %d",&tmp[i].pos1,&tmp[i].pos2); vertices[tmp[i].pos1].limit++; vertices[tmp[i].pos2].limit++; } i=start(); vertices[i].suffix=0; for(k=1;k<verSum;k++) { j=next(i); vertices[j].suffix=vertices[i].suffix+vertices[i].limit; vertices[i].limit=vertices[i].suffix; i=j; } vertices[i].limit=vertices[i].suffix; for(i=0;i<edgSum;i++) { edges[vertices[tmp[i].pos1].limit++]=tmp[i].pos2; edges[vertices[tmp[i].pos2].limit++]=tmp[i].pos1; } while(1) { printf("input two place:"); scanf("%d %d",&source,&sink); visit[source]=reach[source]=1; heapsize=0; push1(source); push2(source); cost[source]=0; curVer=source; while(curVer!=sink) { for(i=vertices[curVer].suffix;i<vertices[curVer].limit;i++) { if(visit[edges[i]]) continue; if(reach[edges[i]]==0) { cost[edges[i]]=cost[curVer]+distance(vertices[curVer].pos,vertices[edges[i]].pos); reach[edges[i]]=1; push2(edges[i]); Insert(edges[i]); prefix[edges[i]]=curVer; } else if(cost[edges[i]]>cost[curVer]+distance(vertices[curVer].pos,vertices[edges[i]].pos)) { cost[edges[i]]=cost[curVer]+distance(vertices[curVer].pos,vertices[edges[i]].pos); Update(edges[i]); prefix[edges[i]]=curVer; } } if(heapsize==0) { break; } curVer=HeapMin(); visit[curVer]=1; push1(curVer); } while(Empty1()) { pop1(); } while(Empty2()) { pop2(); } if(curVer==sink) { printf("distance:%lf\n",cost[sink]); while(curVer!=source) { push(curVer); curVer=prefix[curVer]; } push(source); printf("route:"); while(Empty()) { pop(); } printf("\n"); } else { printf("NULL\n"); } } return 0; }