您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ stack_peek函数代码示例

51自学网 2021-06-03 08:21:08
  C++
这篇教程C++ stack_peek函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中stack_peek函数的典型用法代码示例。如果您正苦于以下问题:C++ stack_peek函数的具体用法?C++ stack_peek怎么用?C++ stack_peek使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了stack_peek函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: test_stack_push

void test_stack_push(){    Stack *s = stack_new();    int a = 1;    int b = 2;    int c = 3;    stack_push(s, &a);    cc_assert(stack_peek(s) == &a,              cc_msg("stack_push: Top stack element not as expected"));    stack_push(s, &b);    cc_assert(stack_peek(s) == &b,              cc_msg("stack_push: Top stack element not as expected"));    stack_push(s, &c);    cc_assert(stack_peek(s) == &c,              cc_msg("stack_push: Top stack element not as expected"));    stack_destroy(s);}
开发者ID:3k,项目名称:Collections-C,代码行数:26,


示例2: test_capacity_one_stack

void test_capacity_one_stack(){    Stack stk_instance = stack_new(1);    Stack *stk = &stk_instance;    StackResult result;    assert(stack_empty(stk));    assert(!stack_full(stk));    stack_peek(stk, &result);    assert(result.status == STACK_EMPTY);    stack_pop(stk, &result);    assert(result.status == STACK_EMPTY);    stack_push(stk, 99, &result);    assert(result.status == STACK_OK);    assert(stack_full(stk));    stack_push(stk, 222, &result);    assert(result.status == STACK_FULL);    stack_peek(stk, &result);    assert(result.data == 99 && result.status == STACK_OK);    stack_pop(stk, &result);    assert(result.data == 99 && result.status == STACK_OK);    assert(stack_empty(stk));}
开发者ID:Rana101,项目名称:data-structures,代码行数:28,


示例3: main

int main(int argc, char const *argv[]){    int arr[] = {10, -15, 3, 2, 5, -2, 1, -1, -2, -3, -3, -10};    int len = sizeof(arr)/sizeof(int);    Stack s;    stack_init(&s, sizeof(int), compar_int);    for (int i = 0; i < len; ++i) {        printf("Pushing %d/n", arr[i]);        stack_push(&s, &arr[i]);        printf("Stack: ");        stack_int_print(&s);        printf("Stack mins: ");        list_int_print(s.mins);        if (!stack_empty(&s))            printf("stack_peek: %d/n",*(int *)stack_peek(&s));    }    while (!stack_empty(&s)) {        void *data = stack_pop(&s);        printf("Popped %d, freeing it./n", *(int *)data);        printf("Stack: ");        stack_int_print(&s);        printf("Stack mins: ");        list_int_print(s.mins);        if (!stack_empty(&s))            printf("stack_peek: %d/n", *(int *)stack_peek(&s));    }    return 0;}
开发者ID:wcastello,项目名称:stuff,代码行数:29,


示例4: hint_try_close

static Nvhint_try_close(SaxDrive dr, const char *name) {    Hint	h = ox_hint_find(dr->hints, name);    Nv		nv;    if (0 == h) {	return 0;    }    for (nv = stack_peek(&dr->stack); 0 != nv; nv = stack_peek(&dr->stack)) {	if (0 == strcasecmp(name, nv->name)) {	    stack_pop(&dr->stack);	    return nv;	}	if (0 == nv->hint) {	    break;	}	if (nv->hint->empty) {	    end_element_cb(dr, nv->val, dr->buf.line, dr->buf.col);	    dr->stack.tail = nv;	} else {	    break;	}    }    return 0;}
开发者ID:gouravtiwari,项目名称:ox,代码行数:25,


示例5: main

int main() {    node* stack = new_stack();    int i;    for (i=0; i<10; i++) {       stack_push(stack, i);    }    assert(stack_peek(stack) == 9);    assert(stack_pop(stack) == 9);    assert(stack_peek(stack) == 8);}
开发者ID:kelvinabrokwa,项目名称:misc,代码行数:10,


示例6: pop_nested_expr

static void pop_nested_expr(ExprQueue *pQueue, ExprStack *pStack){	ExprElement *pPeekElm = stack_peek(pStack);	for (;		pPeekElm != NULL && pPeekElm->type != OPEN_PAREN; 		pPeekElm = stack_peek(pStack))	{		queue_enqueue(pQueue, stack_pop(pStack));	}	stack_pop(pStack); //pop paren}
开发者ID:trey2021,项目名称:expr,代码行数:13,


示例7: pop_lower_order_operations

static void pop_lower_order_operations(ExprQueue *pQueue, ExprOperation *pOperation, 	ExprStack *pStack){	ExprElement *pPeekElm = stack_peek(pStack);	for (;		pPeekElm != NULL && pPeekElm->type == OPERATION			&& is_lower_precedence(pOperation, pPeekElm->value.pOpValue);		pPeekElm = stack_peek(pStack))	{		queue_enqueue(pQueue, stack_pop(pStack));	}}
开发者ID:trey2021,项目名称:expr,代码行数:13,


示例8: hash_set_value

static voidhash_set_value(ParseInfo pi, Val parent, VALUE value) {    rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), value);    if (Yes == pi->options.trace) {	oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);    }}
开发者ID:skaes,项目名称:oj,代码行数:7,


示例9: hash_set_cstr

static voidhash_set_cstr(ParseInfo pi, const char *key, size_t klen, const char *str, size_t len, const char *orig) {    Val	parent = stack_peek(&pi->stack);    if (0 != pi->options.create_id &&	*pi->options.create_id == *key &&	pi->options.create_id_len == klen &&	0 == strncmp(pi->options.create_id, key, klen)) {	if (str < pi->json || pi->cur < str) {	    parent->classname = oj_strndup(str, len);	} else {	    parent->classname = str;	}	parent->clen = len;    } else {	volatile VALUE	rstr = rb_str_new(str, len);	volatile VALUE	rkey = rb_str_new(key, klen);	rstr = oj_encode(rstr);	rkey = oj_encode(rkey);	if (Yes == pi->options.sym_key) {	    rkey = rb_str_intern(rkey);	}	rb_hash_aset(parent->val, rkey, rstr);    }}
开发者ID:dchelimsky,项目名称:oj,代码行数:26,


示例10: test_arbitrary_stack

void test_arbitrary_stack(){    Stack stk_instance = stack_new(0);    Stack *stk = &stk_instance;    StackResult result = { 0, RESULT_INVALID };    int i;    for (i = 0; i < MAX_DEPTH; i++) {        stack_push(stk, i, &result);        assert(result.status == STACK_OK);        result.status = RESULT_INVALID;    }    stack_push(stk, i, &result);    assert(result.status == STACK_FULL);    for (i = 0; i < MAX_DEPTH; i++) {        result.status = 0;        stack_peek(stk, &result);        assert(result.status == STACK_OK);        assert(result.data == MAX_DEPTH - i - 1);        result.status = RESULT_INVALID;        stack_pop(stk, &result);        assert(result.status == STACK_OK);    }    assert(stack_empty(stk));}
开发者ID:Rana101,项目名称:data-structures,代码行数:29,


示例11: stack_peek_float

//pops an element from the stack//  const stack_t* stack - a pointer to the stack to use//  returns float - the float element that was previously at the top of//                  the stackfloat stack_peek_float(const stack_t* stack){  FloatInt_t fi;  fi.e = stack_peek(stack);  return fi.f;}
开发者ID:DavidDiPaola,项目名称:filth,代码行数:11,


示例12: hint_clear_empty

static voidhint_clear_empty(SaxDrive dr) {    Nv	nv;    for (nv = stack_peek(&dr->stack); 0 != nv; nv = stack_peek(&dr->stack)) {	if (0 == nv->hint) {	    break;	}	if (nv->hint->empty) {	    end_element_cb(dr, nv->val, dr->buf.line, dr->buf.col);	    stack_pop(&dr->stack);	} else {	    break;	}    }}
开发者ID:gouravtiwari,项目名称:ox,代码行数:16,


示例13: array_append_num

static voidarray_append_num(ParseInfo pi, NumInfo ni) {    if (ni->infinity || ni->nan) {	oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");    }    rb_ary_push(stack_peek(&pi->stack)->val, oj_num_as_value(ni));}
开发者ID:ebenoist,项目名称:oj,代码行数:7,


示例14: media_entity_graph_walk_next

struct media_entity *media_entity_graph_walk_next(struct media_entity_graph *graph){	if (stack_top(graph) == NULL)		return NULL;	while (link_top(graph) < stack_top(graph)->num_links) {		struct media_entity *entity = stack_top(graph);		struct media_link *link = &entity->links[link_top(graph)];		struct media_entity *next;				if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {			link_top(graph)++;			continue;		}				next = media_entity_other(entity, link);				if (next == stack_peek(graph)) {			link_top(graph)++;			continue;		}				link_top(graph)++;		stack_push(graph, next);	}	return stack_pop(graph);}
开发者ID:DirtyDroidX,项目名称:android_kernel_htc_m8ul,代码行数:33,


示例15: print_operand_stack

void print_operand_stack(struct context *context){    null_check(context);    struct variable *operand;    for (int i=0; (operand = stack_peek(context->operand_stack, i)); i++)        DEBUGPRINT("/t%s/n", variable_value_str(context, operand));}
开发者ID:smorimura,项目名称:filagree,代码行数:7,


示例16: start_fn

voidstart_fn(void *userData, const XML_Char *name, const XML_Char **atts){	struct stack *stk = (struct stack *) userData;	DOM_Node *parent, *child;	int i;	if (stk == NULL || name == NULL || atts == NULL) {		DOM_Exception = DOM_NULL_POINTER_ERR;		return;	}	parent = (DOM_Node *) stack_peek(stk);	if (parent == NULL) {		DOM_Exception = DOM_SYSTEM_ERR;		return;	}	child = DOM_Document_createElement(parent->ownerDocument, name);	if (child == NULL) {		return;	}	for (i = 0; atts[i]; i += 2) {		DOM_Element_setAttribute(child, atts[i], atts[i + 1]);		if (DOM_Exception) {			return;		}	}	if (DOM_Node_appendChild(parent, child) == NULL) {		return;	}	if (stack_push(stk, child) == 0) {		DOM_Exception = DOM_SYSTEM_ERR;	}}
开发者ID:976717326,项目名称:visp,代码行数:34,


示例17: add_value

static voidadd_value(ParseInfo pi, ojcVal val) {    ojcVal	parent = stack_peek(&pi->stack);    if (0 == parent) { // simple add	*pi->stack.head = val;    } else {	switch (parent->expect) {	case NEXT_ARRAY_NEW:	case NEXT_ARRAY_ELEMENT:	    ojc_array_append(&pi->err, parent, val);	    parent->expect = NEXT_ARRAY_COMMA;	    break;	case NEXT_OBJECT_VALUE:	    pi_object_nappend(pi, parent, val);	    if (pi->kalloc) {		free(pi->key);	    }	    pi->key = 0;	    pi->klen = 0;	    pi->kalloc = false;	    parent->expect = NEXT_OBJECT_COMMA;	    break;	case NEXT_OBJECT_NEW:	case NEXT_OBJECT_KEY:	case NEXT_OBJECT_COMMA:	case NEXT_NONE:	case NEXT_ARRAY_COMMA:	case NEXT_OBJECT_COLON:	default:	    ojc_set_error_at(pi, OJC_PARSE_ERR, __FILE__, __LINE__, "expected %s", _ojc_stack_next_str((ValNext)parent->expect));	    break;	}    }}
开发者ID:ohler55,项目名称:ojc,代码行数:35,


示例18: chardata_fn

voidchardata_fn(void *userData, const XML_Char *s, int len){	struct stack *stk = (struct stack *) userData;	DOM_String *str;	DOM_Text *tex;	DOM_Node *parent;	if (stk == NULL || s == NULL || len == 0) {		DOM_Exception = DOM_NULL_POINTER_ERR;		return;	}	parent = (DOM_Node *) stack_peek(stk);	if (parent == NULL) {		DOM_Exception = DOM_SYSTEM_ERR;		return;	}	if ((str = (DOM_String *) malloc(len + 1)) == NULL) {		DOM_Exception = DOM_NO_MEMORY_ERR;		return;	}	memcpy(str, s, len);	str[len] = '/0';	tex = DOM_Document_createTextNode(parent->ownerDocument, str);	free(str);	if (tex == NULL) {		return;	}	DOM_Node_appendChild(parent, tex);	if (DOM_Exception) {		DOM_Document_destroyNode(parent->ownerDocument, tex);	}}
开发者ID:976717326,项目名称:visp,代码行数:35,


示例19: print_paths

int print_paths(struct bitree_node *root){	struct bitree_node *node = root, *dummy;	struct bitree_node *last_visited = NULL, *peek;	struct stack_t parent_stack, *parent = &parent_stack;	struct stack_t path_stack, *paths = &path_stack;	int cnt = 0;	stack_init(parent, NULL);	stack_init(paths, NULL);	while (!stack_is_empty(parent) || node) {		if (node) {			stack_push(parent, (const void *) node);			stack_push(paths, (const void *) node);			node = node->left;		} else {			peek = (struct bitree_node *) stack_peek(parent);			if (peek->right && last_visited != peek->right) {				node = peek->right;			} else {				if (!peek->right && (peek->left != last_visited || !peek->left)) {					fprintf(stdout, "path %d:", ++cnt);					print_path_sum(paths);				}				stack_pop(parent, (void **) &last_visited);				stack_pop(paths, (void **) &dummy);			}		}	}	return cnt;}
开发者ID:jonaschen,项目名称:C-Programming-Library,代码行数:33,


示例20: double_tree

void double_tree(struct bitree *tree){	struct bitree_node *node = tree->root;	struct bitree_node *last_visited = NULL, *peek;	struct stack_t parent_stack, *parent = &parent_stack;	if (tree == NULL)		return;	stack_init(parent, NULL);	while (!stack_is_empty(parent) || node) {		if (node) {			stack_push(parent, (const void *) node);			node = node->left;		} else {			peek = (struct bitree_node *) stack_peek(parent);			if (peek->right && last_visited != peek->right) {				node = peek->right;			} else {				double_tree_node(tree, peek);				stack_pop(parent, (void **) &last_visited);			}		}	}}
开发者ID:jonaschen,项目名称:C-Programming-Library,代码行数:26,


示例21: _st_bst_destroy

static void_st_bst_destroy(st_bst_node_t *root){  st_bst_node_t **pcur;  stack_t        *stack;  // hypothesis: all calls for the stack would not be failed  stack = stack_init(128, g_item_op->null);  (void) stack_push(stack, &g_dummy);  for (pcur = &root; *pcur != g_dummy; ) {    if ((*pcur)->left==g_dummy && (*pcur)->right==g_dummy) {      _st_bst_free_node(*pcur);      *pcur = g_dummy;      // "g_dummy->right == dummy" gives the terminate condition      pcur = stack_peek(stack);      if ((*pcur)->right == g_dummy) {        pcur = stack_pop(stack);      } else {        pcur = &(*pcur)->right;      }    } else {      stack_push(stack, pcur);      if ((*pcur)->left != g_dummy) {        pcur = &(*pcur)->left;      } else {        pcur = &(*pcur)->right;      }    }  }  stack_destroy(stack);}
开发者ID:kiterunner-t,项目名称:krt,代码行数:34,


示例22: array_append_value

static voidarray_append_value(ParseInfo pi, VALUE value) {    rb_ary_push(stack_peek(&pi->stack)->val, value);    if (Yes == pi->options.trace) {	oj_trace_parse_call("append_value", pi, __FILE__, __LINE__, value);    }}
开发者ID:skaes,项目名称:oj,代码行数:7,


示例23: hash_set_num

static voidhash_set_num(struct _ParseInfo *pi, Val parent, NumInfo ni) {    if (ni->infinity || ni->nan) {	oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");    }    rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), oj_num_as_value(ni));}
开发者ID:ebenoist,项目名称:oj,代码行数:7,


示例24: array_append_cstr

static voidarray_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {    volatile VALUE	rstr = rb_str_new(str, len);    rstr = oj_encode(rstr);    rb_ary_push(stack_peek(&pi->stack)->val, rstr);}
开发者ID:ebenoist,项目名称:oj,代码行数:7,


示例25: add_num_value

static voidadd_num_value(ParseInfo pi, NumInfo ni) {    Val	parent = stack_peek(&pi->stack);    if (0 == parent) {	pi->add_num(pi, ni);    } else {	switch (parent->next) {	case NEXT_ARRAY_NEW:	case NEXT_ARRAY_ELEMENT:	    pi->array_append_num(pi, ni);	    parent->next = NEXT_ARRAY_COMMA;	    break;	case NEXT_HASH_VALUE:	    pi->hash_set_num(pi, parent, ni);	    if (parent->kalloc) {		xfree((char*)parent->key);	    }	    parent->key = 0;	    parent->kalloc = 0;	    parent->next = NEXT_HASH_COMMA;	    break;	default:	    oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "expected %s", oj_stack_next_string(parent->next));	    break;	}    }}
开发者ID:aditi-gupta,项目名称:Daily-Update,代码行数:28,


示例26: hash_set_cstr

static voidhash_set_cstr(ParseInfo pi, Val parent, const char *str, size_t len, const char *orig) {    volatile VALUE	rstr = rb_str_new(str, len);    rstr = oj_encode(rstr);    rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), rstr);}
开发者ID:ebenoist,项目名称:oj,代码行数:7,


示例27: add_value

static voidadd_value(ParseInfo pi, VALUE rval) {    Val	parent = stack_peek(&pi->stack);    if (0 == parent) { // simple add	pi->add_value(pi, rval);    } else {	switch (parent->next) {	case NEXT_ARRAY_NEW:	case NEXT_ARRAY_ELEMENT:	    pi->array_append_value(pi, rval);	    parent->next = NEXT_ARRAY_COMMA;	    break;	case NEXT_HASH_VALUE:	    pi->hash_set_value(pi, parent, rval);	    if (0 != parent->key && 0 < parent->klen && (parent->key < pi->json || pi->cur < parent->key)) {		xfree((char*)parent->key);		parent->key = 0;	    }	    parent->next = NEXT_HASH_COMMA;	    break;	case NEXT_HASH_NEW:	case NEXT_HASH_KEY:	case NEXT_HASH_COMMA:	case NEXT_NONE:	case NEXT_ARRAY_COMMA:	case NEXT_HASH_COLON:	default:	    oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "expected %s", oj_stack_next_string(parent->next));	    break;	}    }}
开发者ID:mfittko,项目名称:oj,代码行数:33,


示例28: post_order

void post_order(node* n, void (*f)(int)) {  elt* stack;  stack = stack_init();  node *current, *temp;  current = n;  while (current != NULL || stack != NULL) {    if (current != NULL) {      if (current->right != NULL) {        stack_push(&stack, current->right);      }      stack_push(&stack, current);      current = current->left;    } else {      current = stack_pop(&stack);      if (current->right != NULL && stack != NULL &&          stack_peek(stack)->value == current->right->value) {        temp = current;        current = stack_pop(&stack);        stack_push(&stack, temp);      } else {        (*f)(current->value);        current = NULL;      }    }  }}
开发者ID:gypsydave5,项目名称:c-algorithms,代码行数:27,


示例29: main

int main() {  int elt; // element to be pushed and poped  char c;  // 'switch(c)' of the main loop    // display management  const char *prompt = "> ";  int prompt_count = 1;    print_usage();  printf("%i%s", prompt_count++, prompt);      /*---------------------------  Main loop of the test program  ---------------------------*/  while ( (c = getchar()) != 'Q')  {    switch(c)    {      case 'p':  // put        if (scanf("%i", &elt) != 1) goto error_scanf;             stack_put(elt);        printf("%i/n", elt);        break;              case 'g':  // get        elt = stack_get();        printf("%i/n", elt);        break;      case 'r': // retrieve, cannot use p for peek :-(        elt = stack_peek();          printf("%i/n", elt);        break;                      default:        print_usage();        break;    }    while (getchar() != '/n') {} /* skip end of line */    printf("%i%s", prompt_count++, prompt);    continue;  // all is ok, go to the beginning of the main loop    /*----- ERROR TREATMENT -----*/ error_scanf:    while (getchar() != '/n') {} /* skip end of line */    printf("ERROR: wrong scanf argument/n");    printf("%i%s", prompt_count++, prompt);    continue;/*----- END ERROR TREATMENT -----*/       }  /*--------------------------------------  End of the main loop of the test program  --------------------------------------*/  printf("Quit/n");  return 0;}
开发者ID:lexruee,项目名称:Unifr-System-Programming,代码行数:59,


示例30: peek

void *peek (stack_t stack_in, stack_t stack_out){  /* Balance the outstack */  balance (stack_in, stack_out);  return stack_peek (stack_out);}
开发者ID:wkennington,项目名称:adt,代码行数:8,



注:本文中的stack_peek函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ stack_pop函数代码示例
C++ stack_new函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。