Example #1
0
void fifo_dispose(struct fifo * f) {
    assert(f != NULL);

    stack_dispose(f->s[0]);
    stack_dispose(f->s[1]);
    free(f);
}
Example #2
0
struct fifo * fifo_create(int max_elements) {
    struct fifo * tmp = NULL;
    max_elements = (max_elements < MIN_ELEMENTS)?MIN_ELEMENTS:max_elements;

    tmp = malloc(sizeof(struct fifo));
    if (tmp == NULL) {
        fprintf(stderr, "%s:%d malloc error.\n",
                __func__, __LINE__);
        return NULL;
    }
    
    tmp->s[0] = stack_create(max_elements);
    if (tmp->s[0] == NULL) {
        fprintf(stderr, "%s:%d stack_create error.\n",
                __func__, __LINE__);
        free(tmp);
        return NULL;
    }
    tmp->s[1] = stack_create(max_elements);
    if (tmp->s[1] == NULL) {
        fprintf(stderr, "%s:%d stack_create error.\n",
                __func__, __LINE__);
        stack_dispose(tmp->s[0]);
        free(tmp);
        return NULL;
    }
    tmp->capacity = max_elements;
    tmp->size = EMPTY_SIZE;

    return tmp;
}
Example #3
0
File: tac.c Project: arakan94/ifj15
void free_tac() {
	free(f_list);
	free(ta_table);

	while (!stack_empty(frame_stack)) {
		rm_frame();
	}
	stack_dispose(frame_stack);

	destroy_frame(prep_frame);
}
Example #4
0
int main()
    //@ requires true;
    //@ ensures true;
{
    struct stack *s = create_stack();
    stack_push(s, 10);
    stack_push(s, 20);
    stack_pop(s);
    stack_pop(s);
    stack_dispose(s);
    return 0;
}
Example #5
0
/* main */
int main() {
    init_pool();
    init_env();
    init_stack_root();

    test();

    destroy_pool();
    stack_dispose(stack_root);

    return 0;
}
Example #6
0
int main()
    //@ requires true;
    //@ ensures true;
{
    struct stack *s = create_stack();
    stack_push(s, 10);
    stack_push(s, 20);
    int x = stack_pop(s);
    assert(x == 20);
    int y = stack_pop(s);
    assert(y == 10);
    stack_dispose(s);
    return 0;
}
Example #7
0
int main()
    //@ requires true;
    //@ ensures true;
{
    struct stack *s = create_stack();
    stack_push(s, 10);
    stack_push(s, 20);
    stack_push(s, 30);
    int a = read_int();
    struct neq_a_data *data = malloc(sizeof(struct neq_a_data));
    if (data == 0) abort();
    data->a = a;
    //@ close int_predicate_data(data);
    stack_filter(s, neq_a, data);
    //@ open int_predicate_data(data);
    free(data);
    stack_dispose(s);
    return 0;
}