这篇教程C++ stack_push函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中stack_push函数的典型用法代码示例。如果您正苦于以下问题:C++ stack_push函数的具体用法?C++ stack_push怎么用?C++ stack_push使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了stack_push函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: Recorrer Stack* Recorrer(Maze *m, Point *input){ int i; Stack *paux = NULL; /*pila auxiliar*/ Stack *pcamino = NULL; /*pila del camino seguido*/ EleStack *pele = NULL; /*punto donde nos encontramos*/ EleStack *pelepoint = NULL; /*Punto vecino*/ Point *ppoint = NULL; Point *ppoint2 = NULL; if(!m){ printf("Error pasando el maze/n"); return NULL; } if(!input){ printf("Error pasando el input/n"); return NULL; } paux = stack_ini(); if (!paux){ printf ("Error en reserva memoria paux/n"); return NULL; } pcamino = stack_ini(); if (!pcamino){ printf ("Error reserva memoria pcamino/n"); stack_free (paux); return NULL; } pele = elestack_ini(); if (!pele){ printf ("Error reserva memoria pele/n"); stack_free(paux); stack_free(pcamino); return NULL; } if (!elestack_setInfo(pele, input)){ /*Guardamos el punto input en pele*/ printf ("Error en setInfo de pele/n"); elestack_free(pele); stack_free(paux); stack_free(pcamino); return NULL; } if(!stack_push (paux, pele)){ /*Introducimos pele en la pila auxiliar*/ printf("Error push del input/n"); elestack_free(pele); stack_free(paux); stack_free(pcamino); return NULL; } elestack_free(pele); while (!stack_isEmpty(paux)){ /*mientras la pila auxiliar no esta vacia*/ pele = stack_pop(paux); /*extraemos el punto superior de la pila y nos "situamos" ahi*/ stack_push(pcamino, pele); /*Como visitamos ese punto lo introducimos en el camino*/ point_setSymbol(maze_getPoint(m, point_getCoordinateX((Point *)elestack_getInfo(pele)), point_getCoordinateY((Point *)elestack_getInfo(pele))), VISITADO); /*Modificamos el simbolo del punto a VISITADO, lo guardamos en el laberinto original*/ for(i = 0; i <= DOWN; i++){ /*Comprobamos las 4 direcciones que se pueden seguir dentro de un laberinto*/ pelepoint = elestack_ini(); if(!pelepoint){ printf("Error en elestack_ini/n"); elestack_free(pele); stack_free(paux); stack_free(pcamino); return NULL; } ppoint2 = (Point*)elestack_getInfo(pele); /*Obtenemos el punto de pele*/ if(!ppoint2){ printf("Error al obtener el punto de pele"); elestack_free(pelepoint); elestack_free(pele); stack_free(paux); stack_free(pcamino); return NULL; } ppoint = maze_getNeighborPoint(m, ppoint2, i); /*Obtenemos el punto vecino en la direccion que indica "i"*/ if(!ppoint){ printf("Error ppoint 1/n"); elestack_free(pelepoint); elestack_free(pele); stack_free(paux); stack_free(pcamino); return NULL; } if(!elestack_setInfo(pelepoint, (void*)ppoint)){ /*Asignamos a pelepoint el punto vecino*/ printf("Error setinfo/n"); elestack_free(pelepoint); elestack_free(pele); stack_free(paux); stack_free(pcamino); return NULL; } if(point_getSymbol(ppoint) == SPACE){ /*Introducimos el punto en la pila auxiliar SOLO si es un SPACE*/ if(!stack_push(paux, pelepoint)){ printf("Error al hacer el push de pelepoint"); elestack_free(pelepoint); elestack_free(pele); stack_free(paux); stack_free(pcamino); return NULL; }//.........这里部分代码省略.........
开发者ID:OscarGB,项目名称:Prog-2,代码行数:101,
示例2: daemon_servestatic bool daemon_serve(int s, char *cmd) { /* Do <cmd> for client connected on <s>. */ static Node *null=NULL, **stack=&null; char buf[FILEPATH_MAX]; bool keep_running=true; if( strcmp(cmd, CMD_PUSH) == 0 ) { char *status; if( stack_len(stack) >= STACK_MAX ) { printf("daemon: push request failed (stack full)/n"); status = MSG_ERROR; strcpy(buf, MSG_ERR_STACK_FULL); } else { soc_w(s, MSG_SUCCESS); if( soc_r(s, buf, FILEPATH_MAX) <= 0 ) { printf("daemon: push request failed (read error)/n"); status = MSG_ERROR; strcpy(buf, MSG_ERR_LENGTH); } else { status = MSG_SUCCESS; stack_push(buf, stack); printf("daemon: PUSH `%s'/n", buf); } } soc_w(s, status); soc_w(s, buf); } else if( strcmp(cmd, CMD_POP) == 0 ) { char *status; if( stack_len(stack) > 0 ) { status = MSG_SUCCESS; sprintf(buf, "%s", stack_peek(stack)); stack_drop(stack); printf("daemon: POP `%s'/n", buf); } else { printf("daemon: tried to pop from empty stack/n"); status = MSG_ERROR; sprintf(buf, MSG_ERR_STACK_EMPTY); } soc_w(s, status); soc_w(s, buf); } else if( strcmp(cmd, CMD_PEEK) == 0 ) { char *status; if( stack_len(stack) > 0 ) { status = MSG_SUCCESS; sprintf(buf, "%s", stack_peek(stack)); } else { status = MSG_ERROR; sprintf(buf, MSG_ERR_STACK_EMPTY); } soc_w(s, status); soc_w(s, buf); } else if( strcmp(cmd, CMD_PICK) == 0 ) { char *picked; soc_w(s, MSG_SUCCESS); soc_r(s, buf, MSG_MAX); picked = stack_nth(atoi(buf), stack); if( picked == NULL ) { soc_w(s, MSG_ERROR); soc_w(s, "stack is not quite that deep"); } else { soc_w(s, MSG_SUCCESS); soc_w(s, picked); } } else if( strcmp(cmd, CMD_SIZE) == 0 ) { sprintf(buf, "%d", stack_len(stack)); soc_w(s, buf); } else if( strcmp(cmd, CMD_STOP) == 0 ) { printf("daemon: Shutting down.../n"); soc_w(s, MSG_SUCCESS); keep_running = false; } else { char msg[MSG_MAX + FILEPATH_MAX]; sprintf(msg, "unknown command `%s'", cmd); soc_w(s, msg); } return keep_running;}
开发者ID:qnaal,项目名称:fls,代码行数:84,
示例3: append_call_stack_tabledvoid append_call_stack_tabled(char type, obj_table* table){ obj * o = create_call_block_tabled(type, call_stack_top, table); stack_push(call_stack, o); call_stack_top = (call_block*)o->data;}
开发者ID:jdtatz,项目名称:Cuttlefish,代码行数:5,
示例4: check_rule//.........这里部分代码省略......... /* for the select */ db_key_t keys[2]; db_val_t vals[2]; db_key_t cols[4]; db1_res_t* res; db_row_t* row; db_val_t* val; int i; char *type; int type_len; LM_INFO("checking for '%.*s'./n", rule->len, ZSW(rule->s)); if ((service_len != 11) || (strncasecmp("d2p+sip:fed", service, 11) && strncasecmp("d2p+sip:std", service, 11) && strncasecmp("d2p+sip:dom", service, 11))) { LM_ERR("can only cope with d2p+sip:fed, d2p+sip:std,and d2p+sip:dom " "for now (and not %.*s)./n", service_len, service); return(0); } type = service + 8; type_len = service_len - 8; if (domainpolicy_dbf.use_table(db_handle, &domainpolicy_table) < 0) { LM_ERR("failed to domainpolicy table/n"); return -1; } keys[0]=&domainpolicy_col_rule; keys[1]=&domainpolicy_col_type; cols[0]=&domainpolicy_col_rule; cols[1]=&domainpolicy_col_type; cols[2]=&domainpolicy_col_att; cols[3]=&domainpolicy_col_val; VAL_TYPE(&vals[0]) = DB1_STR; VAL_NULL(&vals[0]) = 0; VAL_STR(&vals[0]).s = rule->s; VAL_STR(&vals[0]).len = rule->len; VAL_TYPE(&vals[1]) = DB1_STR; VAL_NULL(&vals[1]) = 0; VAL_STR(&vals[1]).s = type; VAL_STR(&vals[1]).len = type_len; /* * SELECT rule, att, val from domainpolicy where rule = "..." */ if (domainpolicy_dbf.query(db_handle, keys, 0, vals, cols, 2, 4, 0, &res) < 0 ) { LM_ERR("querying database/n"); return -1; } LM_INFO("querying database OK/n"); if (RES_ROW_N(res) == 0) { LM_DBG("rule '%.*s' is not know./n", rule->len, ZSW(rule->s)); domainpolicy_dbf.free_result(db_handle, res); return 0; } else { LM_DBG("rule '%.*s' is known/n", rule->len, ZSW(rule->s)); row = RES_ROWS(res); for(i = 0; i < RES_ROW_N(res); i++) { if (ROW_N(row + i) != 4) { LM_ERR("unexpected cell count/n"); return(-1); } val = ROW_VALUES(row + i); if ((VAL_TYPE(val) != DB1_STRING) || (VAL_TYPE(val+1) != DB1_STRING) || (VAL_TYPE(val+2) != DB1_STRING) || (VAL_TYPE(val+3) != DB1_STRING)) { LM_ERR("unexpected cell types/n"); return(-1); } if (VAL_NULL(val+2) || VAL_NULL(val+3)) { LM_INFO("db returned NULL values. Fine with us./n"); continue; } LM_INFO("DB returned %s/%s /n",VAL_STRING(val+2),VAL_STRING(val+3)); if (!stack_push(stack, (char *) VAL_STRING(val+2), (char *) VAL_STRING(val+3))) { return(-1); } } domainpolicy_dbf.free_result(db_handle, res); return 1; }}
开发者ID:adubovikov,项目名称:kamailio,代码行数:101,
示例5: mainint main(int argc, char* argv[]){ int i; node * m; /* obligatory */ printf("Hello, World/r/n"); printf("/r/n---/r/n"); /* Node stuff */ printf("Creating and destroying 10000 nodes/r/n"); for (i = 0; i < 10000 ; i++) { int data = i; node * n = build_node(&data); destroy_node(n); } printf("Done/r/n"); printf("/r/n---/r/n"); printf("Building a queue, adding 10000 nodes. Printing out every 1000/r/n"); queue * q = build_queue(); for (i = 0; i < 10000 ; i++) { int data = i; node * n = build_node(&data); queue_push(q, n); } printf("Queue has the size %d/r/n", q->size); for (i = 0; i < 10000 ; i++) { node * n = queue_pop(q); if((i%1000)==0) { printf("Node has the data %d/r/n", *(int*)n->data); } destroy_node(n); } printf("Queue has the size %d/r/n", q->size); destroy_queue(q); printf("/r/n---/r/n"); printf("Building a stack, adding 10000 nodes. Printing out every 1000/r/n"); stack * s = build_stack(); for (i = 0; i < 10000 ; i++) { int data = i; node * n = build_node(&data); stack_push(s, n); } printf("Stack has the size %d/r/n", s->size); for (i = 0; i < 10000 ; i++) { node * n = stack_pop(s); if((i%1000)==0) { printf("Node has the data %d/r/n", *(int*)n->data); } destroy_node(n); } printf("Stack has the size %d/r/n", s->size); destroy_stack(s); printf("/r/n---/r/n"); printf("Building a linked list, adding 10000 nodes. Printing out every 1000/r/n"); llist * l = build_llist(); for (i = 0; i < 10000 ; i++) { int data = i; node * n = build_node(&data); llist_add(l, n); } printf("llist has the size %d/r/n", l->size); printf("Testing arbitrary access.../r/n"); m = llist_get(l, 87); printf("Node has the data %d/r/n", *(int*)m->data); m = llist_get(l, 3487); printf("Node has the data %d/r/n", *(int*)m->data); m = llist_get(l, 287); printf("Node has the data %d/r/n", *(int*)m->data); printf("Testing arbitrary delete.../r/n"); m = llist_get(l, 299); printf("Node has the data %d/r/n", *(int*)m->data); llist_delete(l, 299); m = llist_get(l, 299); printf("Node has the data %d/r/n", *(int*)m->data); printf("Testing mass delete.../r/n");//.........这里部分代码省略.........
开发者ID:carl-ellis,项目名称:c_refresher,代码行数:101,
示例6: convert_in_formula_to_rpn_formula |