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

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

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

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

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

示例1: eval_new

struct eval *eval_new(symlook_fn symlook, void *context){	struct eval *eval;	struct tok *em;	if ((eval = malloc(sizeof *eval)) == NULL) {		PMNO(errno);		return NULL;	}	memset(eval, 0, sizeof *eval);	if ((eval->toks = varray_new(sizeof(struct tok), NULL)) == NULL ||			(eval->opstk = stack_new(4096, NULL)) == NULL ||			(eval->stk = stack_new(4096, NULL)) == NULL ||			(em = varray_get(eval->toks, eval->toki++)) == NULL) {		AMSG("");		eval_del(eval);		return NULL;	}	eval->context = context;	eval->symlook = symlook;	em->type = TOK_TYPE_EMPTY;	stack_push(eval->opstk, em);	return eval;}
开发者ID:OpenSharp,项目名称:NDceRpc,代码行数:27,


示例2: main

int main(void){    int value = 10, v = 11, i;    Student s1 = {12, "student1", "addr1"},s2 = {13, "student2","a1"},             s3 = {15, "stu3", "address3"}, *sptr;    pStack ps = stack_new(sizeof(Student) + 20);    pStack p = stack_new(sizeof(int));    stack_push(p, &value);    stack_push(p, &v);    printf("%d/n", *((int*)stack_top(p)));    stack_pop(p);    printf("%d/n", *((int*)stack_top(p)));        stack_push(ps, &s1);    stack_push(ps, &s2);    sptr = (pStudent)stack_top(ps);    printf("no: %d, name: %s/n", sptr->no, sptr->addr);    stack_pop(ps);    stack_push(ps, &s3);    sptr = (pStudent)stack_top(ps);    printf("no: %d, name: %s/n", sptr->no, sptr->addr);    stack_free(ps);    for (i = 0; i < 100; i++) {        stack_push(p, &i);    }    for (i = 0; i < 100; i++) {        printf("%d ", *((int*)stack_top(p)));        stack_pop(p);    }    stack_free(p);    exit(EXIT_SUCCESS);}
开发者ID:qyh,项目名称:studio,代码行数:35,


示例3: type_constrain_ari

struct stack * type_constrain_ari(struct elt *e1, struct elt *e2){	struct stack *types, *tmp1, *tmp2;	// these will modify the type of e1 and e2 to match arithmetic operation.	// if possible.	if (type_vartype_constrain_ari(e1) == 0) { return NULL; }	if (type_vartype_constrain_ari(e2) == 0) { return NULL; }	if (e1->elttype == E_REG) {		tmp1 = e1->reg->types;	} else {		tmp1 = stack_new();		stack_push(tmp1, &possible_types[(int)e1->cst->type]);	}	if (e2->elttype == E_REG) {		tmp2 = e2->reg->types;	} else {		tmp2 = stack_new();		stack_push(tmp2, &possible_types[(int)e2->cst->type]);	}	types = type_inter(tmp1, tmp2);	if (stack_size(types) == 0) { // float + int		stack_push(types, &possible_types[FLO_T]);	}	if (e1->elttype == E_CST) { stack_free(&tmp1, NULL); }	if (e2->elttype == E_CST) { stack_free(&tmp2, NULL); }	return types;}
开发者ID:uOptim,项目名称:rubic-enseirb,代码行数:33,


示例4: null_check

struct context *context_new(bool state){    struct context *context = (struct context*)malloc(sizeof(struct context));    null_check(context);    context->program_stack = stack_new();    if (state)        stack_push(context->program_stack, program_state_new(context, NULL));    context->operand_stack = stack_new();    context->vm_exception = NULL;    context->runtime = true;    context->num_vars = 0;    context->indent = 0;    return context;}
开发者ID:smorimura,项目名称:filagree,代码行数:15,


示例5: BT_LOGD_STR

struct bt_btr *bt_btr_create(struct bt_btr_cbs cbs, void *data){	struct bt_btr *btr;	BT_LOGD_STR("Creating binary type reader (BTR).");	btr = g_new0(struct bt_btr, 1);	if (!btr) {		BT_LOGE_STR("Failed to allocate one binary type reader.");		goto end;	}	btr->stack = stack_new();	if (!btr->stack) {		BT_LOGE_STR("Cannot create BTR's stack.");		bt_btr_destroy(btr);		btr = NULL;		goto end;	}	btr->state = BTR_STATE_NEXT_FIELD;	btr->user.cbs = cbs;	btr->user.data = data;	BT_LOGD("Created BTR: addr=%p", btr);end:	return btr;}
开发者ID:eepp,项目名称:babeltrace,代码行数:27,


示例6: 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,


示例7: test_stack_push

int test_stack_push(void){    struct stack *s = stack_new();    float *f1 = malloc_float(2.0);    float *f2 = malloc_float(4.0);    float *f3 = malloc_float(8.0);    /* push float 1 */    stack_push(s, f1);    mu_check(fltcmp(s->end->value, f1) == 0);    mu_check(s->size == 1);    mu_check(s->root->value == f1);    mu_check(s->end->prev == NULL);    /* push float 2 */    stack_push(s, f2);    mu_check(fltcmp(s->end->value, f2) == 0);    mu_check(s->size == 2);    mu_check(s->root->value == f1);    mu_check(s->end->prev->value == f1);    mu_check(fltcmp(s->end->prev->value, f1) == 0);    /* push float 3 */    stack_push(s, f3);    mu_check(fltcmp(s->end->value, f3) == 0);    mu_check(s->size == 3);    mu_check(s->root->value == f1);    mu_check(s->end->prev->value == f2);    mu_check(fltcmp(s->end->prev->value, f2) == 0);    stack_destroy(s, free);    return 0;}
开发者ID:wallarelvo,项目名称:evolve,代码行数:33,


示例8: 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,


示例9: inorderTraversal

int * inorderTraversal(struct TreeNode *root, int *returnSize){    int idx, *list = (int *)malloc(sizeof(int) * 256); /* ~~, implement a list? */    struct TreeNode *node;    Stack *stack = stack_new(sizeof(struct TreeNode *));    idx = 0;    node = root;    while (node != NULL) {        stack_push(stack, &node);        node = node->left;    }    while (!stack_is_empty(stack)) {        stack_pop(stack, &node);        list[idx++] = node->val;        node = node->right;        while (node != NULL) {            stack_push(stack, &node);            node = node->left;        }    }    stack_free(stack);    *returnSize = idx;    return list;}
开发者ID:damnever,项目名称:Note,代码行数:26,


示例10: type_vartype_constrain_ari

static int type_vartype_constrain_ari(struct elt *e){	int ret = 0;	struct stack *tmp, *inter;	// TODO: Init this only once at the begining	tmp = stack_new();	stack_push(tmp, &possible_types[FLO_T]);	stack_push(tmp, &possible_types[INT_T]);	if (e->elttype == E_REG) {		inter = type_inter(tmp, e->reg->types);		ret = stack_size(inter);		if (ret != 0) {			// replace old stack with the new one			reg_settypes(e->reg, inter);		}		stack_free(&inter, NULL);	} 		else {		if (e->cst->type != FLO_T && e->cst->type != INT_T) {			ret = 0;		} else {			ret = 1;		}	}	stack_free(&tmp, NULL);	return ret;}
开发者ID:uOptim,项目名称:rubic-enseirb,代码行数:34,


示例11: main

intmain() {  int retval;  char cont;  struct stack *stack;  stack = stack_new(STACK_SIZE);  cont = 1;  while(cont) {    retval = interact(stack);    switch (retval) {    case EXIT_OP:      cont = 0;      break;    case INVALID_CHAR:      printf("Invalid char!/n");      break;    case STACK_UNDERFLOW:      printf("Stack underflow!/n");      break;    case STACK_OVERFLOW:      printf("Stack overflow!/n");      break;    default:      continue;    }  }  stack_free(stack);  return 0;}
开发者ID:oleks,项目名称:components,代码行数:33,


示例12: TestStackCreation

void TestStackCreation(CuTest* tc) {	struct Stack* stack = stack_new(16);	CuAssertIntEquals(tc, 16, stack->size);	CuAssertTrue(tc, stack_is_empty(stack));	stack_del(stack);}
开发者ID:seece,项目名称:tiraimg,代码行数:7,


示例13: main

int main(int argc, char* argv[]) {    struct Stack stack;    struct Program program;    int exit_code = 1, file_nr, size;    FILE * code_file;        stack_new(&stack, 100);    debug(" * created stack of 100");        if (argc > 1) {        for (file_nr = 1; file_nr < argc; file_nr++) {#ifdef DEBUG            printf(" * open file '%s'/n", argv[file_nr]);#endif            code_file = fopen(argv[file_nr], "r");            debug(" * start programm");            size = program_size(code_file);            fseek(code_file, 0, SEEK_SET);            program_new(&program, size);            debug(" * created programm, start reading...");            read_program(code_file, &program);            exit_code = interprete(&stack, &program);            fclose(code_file);        }    } else {        debug(" ! no programm specified, vm will end");        printf("usage: %s {simple-language.slc}/n", argv[0]);    }        return exit_code;}
开发者ID:threez,项目名称:simple_vm,代码行数:31,


示例14: malloc

Context *context_new(void){	Context *context;	context = (Context *) malloc(sizeof(Context));	if (NULL == context) {		goto err_malloc;	}	context->stack = stack_new((FreeFunc *) value_free_ignoring_symbols);	if (NULL == context->stack) {		goto err_malloc_stack;	}	context->map = map_new((FreeFunc *) value_free);	if (NULL == context->map) {		goto err_malloc_map;	}	context_builtin(context);	context->defining_variable = FALSE;	return context;err_malloc_map:	free(context->stack);err_malloc_stack:	free(context);err_malloc:	return NULL;}
开发者ID:yaraki,项目名称:forsh,代码行数:25,


示例15: 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,


示例16: sizeof

signal2_t *signal2_new(){	signal2_t * obj = (signal2_t *)calloc(1, sizeof(struct s_signal2));	obj->slot2s_stack = stack_new(sizeof(slot2_t *));	return obj;}
开发者ID:felipe-lavratti,项目名称:marsh,代码行数:8,


示例17: main

main(){	int no,i,j,k=0;	int **info;	info=malloc(MAX_FLOORS*sizeof(int*));	person p;	Stack *up,*down;  //up and down lists contain persons going up and down	up=stack_new();	down=stack_new();	for(i=0;i<10;i++){		scanf("%d",&no);  //number of persons in lift		info[i]=malloc(2*no*sizeof(int));		for(j=0;j<2*no;j++){			scanf("%d",&info[i][j]);			if(j%2==1&&info[i][j]>i){				p.time=info[i][j-1];				p.id=k; //k is the identity of person.				k++;				p.from_floor=i;				p.to_floor=info[i][j];				up=stack_push(up,p);			}			if(j%2==1&&info[i][j]<i){				p.time=info[i][j-1];				p.id=k;				k++;				p.from_floor=i;				p.to_floor=info[i][j];				down=stack_push(down,p);			}			}	}	LIFT *lift1,*lift2;	lift1=malloc(sizeof(LIFT));	lift2=malloc(sizeof(LIFT));	//initialising lifts	lift1->list=stack_new();	lift2->list=stack_new();	lift1->size=0;	lift2->size=0;	lift2->position=0;	lift1->position=0;	lift1->status=0;	lift2->status=0;	//initialisations	simulate2 (up,down,lift1,lift2);}
开发者ID:miryala,项目名称:lift,代码行数:46,


示例18: b_push

void b_push(struct stack *balancer, struct node *n, int thresh) {    struct stack *s = b_current_stack(balancer);    if (s == NULL || s->n_items >= thresh) {        s = stack_new();        s_push(balancer,node_new(s));    }    s_push(s,n);}
开发者ID:jackdoe,项目名称:cracking-the-coding-interview,代码行数:9,


示例19: type_constrain_boo

struct stack * type_constrain_boo(struct elt *e1, struct elt *e2){	if (0 == type_vartype_constrain_boo(e1)) { return NULL; }	if (0 == type_vartype_constrain_boo(e2)) { return NULL; }	struct stack *types = stack_new();	stack_push(types, &possible_types[BOO_T]);	return types;}
开发者ID:uOptim,项目名称:rubic-enseirb,代码行数:10,


示例20: init_cache

static void init_cache(void){/*	int i;	for (i=0;i < MAXSHIFT;++i) {		mem_cache[i] = stack_new(10240);	}*/	iov_cache = stack_new(10240);	atexit(destroy_cache);}
开发者ID:gwtony,项目名称:wsocket,代码行数:10,


示例21: test_new

void test_new(){	int capacity = 16;	stack_int_t stack = stack_new(capacity);	ok(		stack.capacity == capacity &&		stack.array != NULL,		"stack_new."	);}
开发者ID:modulated,项目名称:uti-c,代码行数:11,


示例22: tentar_imprimir_pedaco_codigo

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