int main(void) { //user_tests (); srand (time (NULL)); stack_t * st1 = stack_t_make_stack(7, 1); stack_t * st2 = stack_t_make_stack(2, 2); stack_t_print(st1); stack_t_print (st2); // stack_t * st1 = stack_t_new(); //stack_t * st2 = stack_t_new (); stack_subscribe_full (st1, st2, stack_Event); stack_subscribe_full (st2, st1, stack_Event); stack_subscribe_empty (st1, st2, stack_Event); stack_subscribe_empty (st2, st1, stack_Event); user_t users1[4] = {{"Vasya"}, {"Galya"}}; user_t users2[3] = {{"Petya"}, {"Roma"}}; for(int i = 0; i < 2; i++) { stack_subscribe_multi (st1, &users1[i], stack_Event); stack_subscribe_multi(st2, &users2[i], stack_Event); } stack_t_print(st1); stack_t_print (st2); while(1) { stack_t_rand_choice(st1, st2); } stack_delete(st1); stack_delete(st2); return 0; }
extern int ct_index_of(node_t *root, PyObject *key) { node_t *node = root; int index = 0; int go_down = 1; node_stack_t *stack; stack = stack_init(32); for (;;) { if ((LEFT_NODE(node) != NULL) && go_down) { stack_push(stack, node); node = LEFT_NODE(node); } else { if (ct_compare(KEY(node), key) == 0) { stack_delete(stack); return index; } index++; if (RIGHT_NODE(node) != NULL) { node = RIGHT_NODE(node); go_down = 1; } else { if (stack_is_empty(stack)) { stack_delete(stack); return -1; } node = stack_pop(stack); go_down = 0; } } } }
int bracket_match(const char* buf, int buf_len) { int i, ret = 0; char ch; stack_t s; if (NULL == buf || buf_len <= 0) { fprintf(stderr, "arguments invalid ..."); exit(0); } s = stack_create(128); for (i = 0; i < buf_len; ++i) { ch = buf[i]; if ('(' == ch || '[' == ch) stack_push(s, ch); else if (')' == ch) { if (stack_empty(s) || '(' != stack_pop(s)) break; } else if (']' == ch) { if (stack_empty(s) || '[' != stack_pop(s)) break; } else break; } if (stack_empty(s)) ret = 1; stack_delete(&s); return ret; }
struct stack_s* stack_new(int num, int element_size) { struct stack_s* ret = (struct stack_s*)malloc(sizeof(struct stack_s)); if(NULL != ret) { memset(ret, 0, sizeof(*ret)); ret->array = array_new(num, element_size); if(NULL != ret->array) { ret->element_num = num; ret->top = 0; } else { stack_delete(ret); ret = NULL; } } return ret; }
stack* stack_expansion(stack* stk, int new_size){ double* buf = NULL; int i = 0; stack* new_stack = stack_create(new_size); buf = (double*) calloc (stk -> size, sizeof(double*)); if (stack_is_valide(stk)) { if (buf) { for (i = 0; i <= stk -> head; ++i) { buf[i] = stk -> data[i]; } stack_delete(stk); i--; new_stack -> head = i; if (new_stack -> head + 1) do new_stack -> data[i] = buf[i]; while (--i + 1); free(buf); buf = NULL; return new_stack; } errno = ENOMEM; return stk; } return 0; }
void signal2_delete(signal2_t * obj) { PTR_CHECK(obj, "signal2"); stack_delete(obj->slot2s_stack); free(obj); }
int ar_delete (ar warehouse) { /* delete the activation records table */ int err; if (warehouse == NULL) { FI_errno = FI_BUGERR; return 0; } err = stack_delete (warehouse -> entries); free (warehouse); return err; }
int main() //MAIN { // struct stack * s1; //deklaracja, ¿e s1 to typ stack s1 = stack_create(1); //tworzy stos //z->dane=111; //s1->data = 11; //printf("aaa"); stack_delete(s1); //usuniêcie s1 \\\\\\podaje zmienn¹ system("pause"); //przytrzymanie programu return 0; //zwrócenie 0 }
/* Function added to delete the memory allocated for AND nodes of a decorated syntax tree Decorated syntax tree is a conjuntion of simple selection predicates */ void delDecoratedSyntreeANDnodes(syntree *arg) { stack *s; stack *and_stack; syntree *and_tree; ASSERT (arg); s = stack_new(); and_stack = stack_new(); // Store the nodes with type AND_TYPE push(s, arg); while(!is_stack_empty(s)) { arg = pop(s); // This node should not be traversed as it contains specific nodes different from syntree. if (arg->type == FT_PREDICATE_TYPE) { continue; } if (arg->type == AND_TYPE) { push(and_stack, arg); } if (arg->right_tree) push(s, arg->right_tree); if (arg->left_tree) push(s, arg->left_tree); } // Free the memory for all the AND nodes while(!is_stack_empty(and_stack)) { and_tree = pop(and_stack); syntree_delete_root_node(and_tree); } stack_delete(s); stack_delete(and_stack); }
int main(void) { A* a = malloc(sizeof(A)), *b = malloc(sizeof(A)), *c = NULL; List* l = list_init(); Stack* s = stack_init(); Queue* q = queue_init(); DoubleLinkedList* d = dll_init(); printf("a: %d\nB: %d\nc: %d\n", (int)a, (int)b, (int)c); a->a1 = 1; a->a2 = 'c'; b->a1 = 2; b->a2 = 'a'; printf("\n=== LIST TEST ===\n"); list_add(l, a, 0); list_append(l, b); list_remove(l, 0); list_print(l); c = list_get(l, 0); printf("c: %d\n", (int)c); list_delete(l); printf("\n=== STACK TEST ===\n"); stack_push(s, b); stack_push(s, a); stack_pop(s); stack_print(s); c = stack_peek(s); printf("c: %d\n", (int)c); stack_delete(s); printf("\n=== QUEUE TEST ===\n"); queue_push(q, a); queue_push(q, b); queue_pop(q); queue_print(q); c = queue_peek(q); printf("c: %d\n", (int)c); queue_delete(q); printf("\n=== DOUBLE LINKED LIST TEST ===\n"); dll_add(d, b, 0); dll_prepend(d, a); dll_remove(d, 1); dll_print(d); c = dll_get(d, 0); printf("c: %d\n", (int)c); dll_delete(d); free(a); free(b); return 0; }
/** * Dispose of a userdata * @param u the object to dispose */ void userdata_dispose( userdata *u ) { if ( u != NULL ) { if ( u->rules != NULL ) u->rules = recipe_dispose( u->rules ); if ( u->ignoring != NULL ) stack_delete( u->ignoring ); if ( u->range_stack != NULL ) stack_delete( u->range_stack ); if ( u->spell_config != NULL ) delete_aspell_config(u->spell_config); if ( u->spell_checker != NULL ) delete_aspell_speller(u->spell_checker); if ( u->last_word != NULL ) free( u->last_word ); if ( u->dest_map != NULL ) hashmap_dispose( u->dest_map ); // we don't own the hh_exceptions free( u ); } }
extern node_t * ct_node_at(node_t *root, int index) { node_t *node = root; int counter = 0; int go_down = 1; node_stack_t *stack; if (index < 0) return NULL; stack = stack_init(32); for(;;) { if ((LEFT_NODE(node) != NULL) && go_down) { stack_push(stack, node); node = LEFT_NODE(node); } else { if (counter == index) { stack_delete(stack); return node; } counter++; if (RIGHT_NODE(node) != NULL) { node = RIGHT_NODE(node); go_down = 1; } else { if (stack_is_empty(stack)) { stack_delete(stack); return NULL; } node = stack_pop(stack); go_down = 0; } } } }
static void destroy_cache(void) { void *mem; // int i; // for (i=0;i < MAXSHIFT;++i) { // while ((mem=(void*)stack_pop_nb(mem_cache[i]))!=NULL) { // free(mem); // } // } while ((mem=(void*)stack_pop_nb(iov_cache))!=NULL) { free(mem); } stack_delete(iov_cache); }
int main() { Stack* stack = stack_new(); stack_push(stack, 1); stack_push(stack, 2); stack_push(stack, 3); stack_push(stack, 4); printf("SIZE: %i\n", stack_size(stack)); while (!stack_empty(stack)) { printf("%i\n", stack_top(stack)); stack_pop(stack); } stack_delete(stack); }
/* Function to return the number of tuple variables and the tuple variable and the data source names from the FROM_CLAUSE The function returns all the tuple variables in the tuple_var_name list, the data source names in the data_source_name list and the number of tuple variables as num_tuple_var */ int get_name_tuple_variables(syntree *arg, List *tuple_var_name, List *data_source_name) { stack *s; int num_tuple_var = 0; ASSERT (arg); ASSERT(tuple_var_name); ASSERT(data_source_name); s = stack_new(); /* Traversal of tree */ push(s, arg); while(!is_stack_empty(s)) { arg = pop(s); /* Check for DATA SOURCE NAME TYPE and data source names */ if (arg->type == DATASRC_NAME_TYPE) { ASSERT (arg->right_tree); List_insertElement(data_source_name, arg->right_tree->datum); num_tuple_var++; } /* Check for DATA SOURCE SPEC TYPE and find the tuple variable names */ if (arg->type == DATASRC_SPEC_TYPE) { ASSERT (arg->right_tree); List_insertElement(tuple_var_name, arg->right_tree->datum); } if (arg->right_tree) push(s, arg->right_tree); if (arg->left_tree) push(s, arg->left_tree); } stack_delete(s); return num_tuple_var; }
static void _do_bst_traverse_inorder_iterative_(TreeNode *root, Visitor visitor) { Stack stk; StackResult res; stk = stack_new(0); while (root != NULL || !stack_empty(stk)) { if (root != NULL) { /* walk down the left subtree. */ stack_push(stk, root, &res); root = root->left; } else { /* no subtree to process; visit the parent node. */ stack_pop(stk, &res); root = res.data; /* Now is the time to process this node data! */ visitor(VISIT_ELEMENT, root->key); root = root->right; /* inspect the right subtree. */ } }; stack_delete(stk); }
int main(void){ int i; stack_t* s; pessoa p; stack_initialize(&s,constructor_pessoa,destructor_pessoa); for(i=0;i<5;i++){ printf("Cadastrando pessoa %d\n",i+1); cadastra_pessoa(&p); stack_push(s,&p); } while(!stack_empty(s)){ printf("\n**Imprimindo pessoa**\n"); p = *(pessoa*) stack_top(s); stack_pop(s); imprime_pessoa(&p); printf("\n"); } stack_delete(&s); return 0; }
int main(int argc, char **argv) { stack_t *s; line_t current_line_type; state_t last_block_type; state_t top_block_type; stack_init(&s); char line[1024]; while(fgets(line, 1024, stdin)) { current_line_type = deduce_line_type(line); last_block_type = stack_top(s); lookup(current_line_type, last_block_type)(s); /* if (current_line_type != L_OTHER) { stack_print(s); } */ top_block_type = stack_first(s); if ((top_block_type == S_IF || top_block_type == S_EMPTY) && !(stack_size(s) == 1 && current_line_type == L_IF) && !(stack_size(s) == 0 && current_line_type == L_ENDIF)) { fprintf(stdout, "%s", line); } } stack_delete(&s); return 0; }
void op_f(stack_t *s) { const MXT_STYPE *i1 = stack_cend(s); const MXT_STYPE *i2 = stack_cbegin(s); int f = 1; printf("["); do { --i1; if(!f) printf(", "); printf("%.2lf", *i1); f = 0; } while(i1 != i2); printf("]\n"); #ifdef MXT_SET_EMPTY stack_delete(s); stack_init(s); #endif }
int get_num_tuple_variables(syntree *arg, List *datasrc_names) { stack *s; int num_var = 0; ListElement *cursor; ASSERT (arg); ASSERT (datasrc_names); s = stack_new(); /* Pre-Order traversal of tree */ push(s, arg); while(!is_stack_empty(s)) { arg = pop(s); // In case of a free text predicate, don't traverse this subtree since it contains special tree nodes // that differ from general syntree structure. if (arg->type == FT_PREDICATE_TYPE) { continue; } if (arg->type == DOT_TYPE) { /* check if the datasrc is already present in the list */ int found = 0; char *temp_name; for (temp_name = (char *)List_getFirst(datasrc_names, &cursor); temp_name; temp_name = (char *)List_getNext(&cursor)) { /* Left tree of dot node is the data source name */ if (tm_strcmp(get_chars(arg->left_tree->datum), temp_name) == 0) { /* dtasrc already present in the list */ found = 1; break; } } if (!found) { /* Left tree of dot node is the data source name. ** datasrc not present. Insert it now. */ ASSERT (arg->left_tree); List_insertElement(datasrc_names, get_chars(arg->left_tree->datum)); //logwrite("%d", arg->left_tree->type); num_var++; } } if (arg->right_tree && arg->type != DOT_TYPE) push(s, arg->right_tree); if (arg->left_tree) push(s, arg->left_tree); } stack_delete(s); return num_var; }
int main(int argc, char * argv[]) { setvbuf(stdout, NULL, _IONBF, 0); //will not compile till you provide a declaration for stack Stack* stack = stack_init(); if (stack == NULL) { fprintf(stderr, STR_ERR_MEM); return EXIT_FAILURE; } stackpointer = stack; //to pass into parse_input FuncInfo funcInfo; printf(STR_WELCOME); printf(STR_PROMPT); //to store strings from stdin char readin[BUFSIZ]; while (fgets(readin, BUFSIZ, stdin) != NULL) { if (feof(stdin)) { break; } //parse input int r = parse_input(&funcInfo, readin); //input could not be parsed, continue to next iteation if (r == -1) { printf("\n"); printf(STR_PROMPT); continue; } //call appropriate function switch (funcInfo.func) { case 1: push(funcInfo.word); break; case 2: pop(); break; case 3: peek(); break; case 4: print(); break; case 5: check(funcInfo.word); break; default: printf(STR_ERR_UNKNOWN); } printf("\n"); printf(STR_PROMPT); } //destruct stack stack_delete(); printf("quit\n"); return EXIT_SUCCESS; return 0; }
/** * This will be called repeatedly * @param name the name of the range * @param atts a NULL-terminated array of XML attributes. * These get turned into STIL annotations * @param reloff relative offset for this range * @param len length of the range * @param dst the output file handle * @param contents the contents of an empty range * @param content_len length of the content * @param first 1 if this is the first range * @param dst the open file descriptor to write to */ int STIL_write_range( UChar *name, UChar **atts, int removed, int reloff, int len, UChar *contents, int content_len, int first, dest_file *dst ) { int res=1; stack *tofree = stack_create(); if ( tofree != NULL ) { int size = calc_range_size(removed,content_len,first,atts); UChar **write_array = calloc(size,sizeof(UChar*)); if ( write_array != NULL ) { int i = 0; UChar u_reloff[16]; u_itoa(reloff,u_reloff,16); UChar u_len[16]; UChar *q_name = quote_string(name,u_strlen(name)); UChar *q_contents = quote_string(contents,content_len); stack_push(tofree,write_array); stack_push(tofree,q_name); stack_push(tofree,q_contents); u_itoa(len,u_len,16); if ( !first ) write_array[i++] = U_COMMANL; write_array[i++] = U_RANGE_START; write_array[i++] = U_NAME; write_array[i++] = q_name; write_array[i++] = U_COMMANL; write_array[i++] = U_RELOFF; write_array[i++] = u_reloff; write_array[i++] = U_COMMANL; write_array[i++] = U_LEN; write_array[i++] = u_len; write_array[i++] = U_COMMANL; if ( content_len > 0 ) { write_array[i++] = U_CONTENT; write_array[i++] = q_contents; write_array[i++] = U_COMMANL; } if ( removed ) { write_array[i++] = U_REMOVED; write_array[i++] = U_TRUE; write_array[i++] = U_COMMANL; } if ( atts[0] != NULL ) { int k = 0; write_array[i++] = U_ANNOTATIONS; while ( atts[k] != NULL ) { UChar *q_name = quote_string( atts[k], u_strlen(atts[k]) ); stack_push(tofree,q_name); UChar *q_value = quote_string( atts[k+1], u_strlen(atts[k+1]) ); stack_push(tofree,q_value); if ( k > 0 ) write_array[i++] = U_COMMA; write_array[i++] = U_ANNOTATION; write_array[i++] = q_name; write_array[i++] = U_COLON; write_array[i++] = q_value; write_array[i++] = U_ANNOTATION_END; k += 2; } write_array[i++] = U_ANNOTATIONS_END; } write_array[i++] = U_RANGE_END; write_utf16_array( write_array, size, dst ); while ( !stack_empty(tofree) ) free( stack_pop(tofree)); } stack_delete(tofree); } else { fprintf(stderr,"STIL: Failed to allocate stack\n"); res = 0; } return res; }
void testStack() { // Create stack* my_stack = NULL; stack* dummy_stack = NULL; assert(stack_create(&my_stack) == 0); // Successfully create assert(stack_create(&dummy_stack) == 0); // Successfully create assert(stack_get_size(my_stack) == 0); // 0 size int a = 3; int b = 4; double c = 5.12; char d = 'c'; char str[20] = "Hello World"; // Successful pushes assert(stack_push(my_stack, &a, sizeof(a)) == 0); assert(stack_push(my_stack, &b, sizeof(b)) == 0); assert(stack_push(my_stack, &c, sizeof(c)) == 0); assert(stack_push(my_stack, &d, sizeof(d)) == 0); assert(stack_push(my_stack, str, strlen(str)) == 0); // Bad pushes: assert(stack_push(NULL, &a, sizeof(a)) != 0); assert(stack_push(my_stack, NULL, sizeof(a)) != 0); assert(stack_push(my_stack, &a, 0) != 0); assert(stack_get_size(my_stack) == 5); // 5 items int a2; int b2; double c2; char d2; char str2[20]; // Bad pop: assert(stack_pop(NULL, &a) != 0); assert(stack_pop(dummy_stack, &a) != 0); assert(stack_pop(my_stack, NULL) != 0); // Successful pop: assert(stack_get_data_size(my_stack) <= 20); assert(stack_pop(my_stack, str2) == 0 && strcmp(str,str)==0); assert(stack_get_data_size(my_stack) == sizeof(d2)); assert(stack_pop(my_stack, &d2) == 0 && d==d2); assert(stack_get_data_size(my_stack) == sizeof(c2)); assert(stack_pop(my_stack, &c2) == 0 && c==c2); assert(stack_get_data_size(my_stack) == sizeof(b2)); assert(stack_pop(my_stack, &b2) == 0 && b==b2); assert(stack_get_data_size(my_stack) == sizeof(a2)); assert(stack_pop(my_stack, &a2) == 0 && a==a2); // Bad pop assert(stack_pop(my_stack, &a2) != 0); // Cleanup assert(stack_delete(my_stack) == 0); // Successfully create assert(stack_delete(dummy_stack) == 0); // Successfully create printf("Stack: Success\n"); }
void test_stack( void ) { unsigned int loop, cpu_count; struct stack_state *ss; thread_state_t *thread_handles; /* TRD : there are 5 tests 1. single reader thread per CPU - stack always empty 2. single writer thread per CPU - stack always full 3. one reader and one writer thread per CPU - stack balanced 4. one reader and two writer threads per CPU - stack grows 5. two reader and one writer thread per CPU - stack tends to empty */ cpu_count = abstraction_cpu_count(); printf( "\n" "Stack Test\n" "==========\n" ); // TRD : 1. single reader thread per CPU printf( "\n" "1. single reader thread per CPU\n" "===============================\n" ); stack_new( &ss, 10000 ); thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 1 ); for( loop = 0 ; loop < cpu_count ; loop++ ) abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_reader, ss ); for( loop = 0 ; loop < cpu_count ; loop++ ) abstraction_thread_wait( thread_handles[loop] ); stack_delete( ss, NULL, NULL ); free( thread_handles ); // TRD : 2. single writer thread per CPU printf( "\n" "2. single writer thread per CPU\n" "===============================\n" ); stack_new( &ss, 10000 ); thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 1 ); for( loop = 0 ; loop < cpu_count ; loop++ ) abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_writer, ss ); for( loop = 0 ; loop < cpu_count ; loop++ ) abstraction_thread_wait( thread_handles[loop] ); stack_delete( ss, NULL, NULL ); free( thread_handles ); // TRD : 3. one reader and one writer thread per CPU printf( "\n" "3. one reader and one writer thread per CPU\n" "===========================================\n" ); stack_new( &ss, 10000 ); thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 2 ); for( loop = 0 ; loop < cpu_count ; loop++ ) { abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_reader, ss ); abstraction_thread_start( &thread_handles[loop+cpu_count], loop, stack_internal_thread_writer, ss ); } for( loop = 0 ; loop < cpu_count * 2 ; loop++ ) abstraction_thread_wait( thread_handles[loop] ); stack_delete( ss, NULL, NULL ); free( thread_handles ); // TRD : 4. one reader and two writer threads per CPU printf( "\n" "4. one reader and two writer threads per CPU\n" "============================================\n" ); stack_new( &ss, 10000 ); thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 3 ); for( loop = 0 ; loop < cpu_count ; loop++ ) { abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_reader, ss ); abstraction_thread_start( &thread_handles[loop+cpu_count], loop, stack_internal_thread_writer, ss ); abstraction_thread_start( &thread_handles[loop+cpu_count*2], loop, stack_internal_thread_writer, ss ); } for( loop = 0 ; loop < cpu_count * 3 ; loop++ ) abstraction_thread_wait( thread_handles[loop] ); stack_delete( ss, NULL, NULL ); free( thread_handles ); // TRD : 5. two reader and one writer thread per CPU printf( "\n" "5. two reader and one writer thread per CPU\n" "===========================================\n" ); stack_new( &ss, 10000 ); thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 3 ); for( loop = 0 ; loop < cpu_count ; loop++ ) { abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_reader, ss ); abstraction_thread_start( &thread_handles[loop+cpu_count], loop, stack_internal_thread_reader, ss ); abstraction_thread_start( &thread_handles[loop+cpu_count*2], loop, stack_internal_thread_writer, ss ); } for( loop = 0 ; loop < cpu_count * 3 ; loop++ ) abstraction_thread_wait( thread_handles[loop] ); stack_delete( ss, NULL, NULL ); free( thread_handles ); return; }
void build_RCG(RCG *graph, syntree *arg) { ASSERT(graph); if (arg == NULL) return; if (arg->type == AND_TYPE || arg->type == WHEN_CLAUSE_TYPE) { /* left and right tree of the arg are collections of predicates */ build_RCG(graph, arg->left_tree); build_RCG(graph, arg->right_tree); } else { /* Node is other than the AND and WHEN_CLAUSE type. Hence is the root of the predicate */ int num_var; syntree *p, *predicate_root; stack *s; List *datasrc_names; RCG_node *node; p = arg; predicate_root = arg; s = stack_new(); /* Get the num of tuple variables in the predicate */ datasrc_names = List_new(); num_var = get_num_tuple_variables(arg, datasrc_names); // Delete the backbone of the list containing the REF to the data source names // The actual data source names get deleted during drop trigger List_deleteBackbone(datasrc_names); // Add the constant only predicate with no variables to every RCG node. // Also make sure it is not a boolean predicate like (WHEN TRUE - any trigger // without a WHEN CLAUSE is considered a WHEN TRUE predicate). if (num_var == 0 && arg->type != BOOL_LIT_TYPE) { // Is a selection predicate. ListElement *cursor; RCG_node *rcg_node; for (rcg_node = (RCG_node *)List_getFirst(graph->nodes, &cursor); rcg_node; rcg_node = (RCG_node *)List_getNext(&cursor)) { List_insertElement(rcg_node->selection_predicates_list, predicate_root); } } else if (num_var == 2) { /* Is a join predicate */ /* Pre-Order traversal of tree without recursion */ push(s, p); while(!is_stack_empty(s)) { p = pop(s); if (p->type == ID_TYPE && p->augtype == DATA_SRC_TYPE) { /*node is of DATASRC type */ /* Get the index of datasrc in the RCG */ node = get_node_from_RCG(get_chars(p->datum), graph); if (!node->already_inserted) { /* add the predicate root to the join predicate list of index node */ List_insertElement(node->join_predicates_list, predicate_root); /* Make an entry that it is inserted in index node */ node->already_inserted = 1; } } if (p->right_tree && p->type != DOT_TYPE) push(s, p->right_tree); if (p->left_tree) push(s, p->left_tree); } /* reset the already_inserted value */ reset(graph); /* predicate inserted in all nodes */ stack_delete(s); return; } else if (num_var == 1) { /* IS a selection predicate */ /* Pre-Order traversal of tree without recursion */ push(s, p); while(!is_stack_empty(s)) { p = pop(s); // A FT_PREDICATE_TYPE node must not be found here, the traversal must have ended before itself. ASSERT (p->type != FT_PREDICATE_TYPE); if (p->type == ID_TYPE && p->augtype == DATA_SRC_TYPE) { /*node is of DATASRC type */ /* Get the index of datasrc in the RCG */ node = get_node_from_RCG(get_chars(p->datum), graph); /* add the predicate root to the selection predicate list of index node */ List_insertElement(node->selection_predicates_list, predicate_root); /* Predicate inserted. No need to traverse any further*/ stack_delete(s); return; } if (p->right_tree && p->type != DOT_TYPE) push(s, p->right_tree); if (p->left_tree) push(s, p->left_tree); } /* not reached - to avoid compile time error */ return; } // We don't support zero tuple variable predicates like 0 = 0 or 0 + 5 < 10 // To process complex predicates involving more than 2 tuple var else if (num_var > 2) { // Predicates with more than two tuple variables use catch all list List_insertElement(graph->catch_all, predicate_root); stack_delete(s); return; } stack_delete(s); } }
int main(){ char buf[MAXLINE] = ""; double num1 = 0,num2 = 0, num = 0; int i = 0; stack* stk = stack_create(MAXLINE); freopen("log.txt", "w+", stderr); fprintf(stderr, "No problem"); //clean log file fgets(buf, MAXLINE, stdin); while(buf[i] != '\n'){ switch (buf[i]) { case '+': case '*': case '/': case '^': case 'l': assert(stack_head(stk) >= 1); num1 = pop(stk); num2 = pop(stk); num = calculate(num2, num1, buf[i]); push(stk, num); break; case '-': if (buf[i + 1] == ' '){ assert(stack_head(stk) >= 1); num1 = pop(stk); num2 = pop(stk); num = calculate(num2, num1, buf[i]); push(stk, num); } else { i = float_reader(buf, i, &num); push(stk, num); } break; case '1': case '2': case '3': case '4': case '5': \ case '6': case '7': case '8': case '9': case '0': i = float_reader(buf, i, &num); push(stk, num); break; default: printf("incorrect operation"); abort(); } ++i; } if (stack_head(stk) != 0){ errno = EINVAL; perror("Incorrect input expression\n"); abort(); } if (errno != 0){ printf("program failed"); abort(); } printf("%lg\n", pop(stk)); stack_delete(stk); return 0; }
void op_c(stack_t *s) { stack_delete(s); stack_init(s); }