// it's out_size based so insz is useless int unctw(unsigned char *in, int insz, unsigned char *out, int outsz) { unsigned char let; unsigned int phase, i, o = 0, codebits; init_CTWsettings(); ardecinit(in, insz); if (!init_filebuffer()) return(-1); for(nrsymbols = 0; nrsymbols <= settings.treedepth && nrsymbols < outsz; nrsymbols++) { let = 0; for(phase = 0; phase < 8; phase++) let = (let << 1) | ardec(STEPHALF); filebuffer[nrsymbols] = let; if(o >= outsz) return(o); out[o++] = let; } if (!init_tree(let)) return(-1); init_ctxstring(); /* start decoding */ for(i = settings.treedepth + 1; i < outsz; i++) { let = Decode(); if(o >= outsz) return(o); out[o++] = let; } ardecexit(&codebits); free_memory(); return(o); }
void make_new_node(struct p_tree *ch_l, struct p_tree *ch_r) { struct p_tree *node = NULL; int i; node = (struct p_tree *) ckalloc(sizeof(struct p_tree)); init_tree(node); ch_r->depth = ch_r->depth + 1; assign_node(node, ch_l, NO_DEALLOC); node->depth = ch_l->depth + 1; node->nid = count_node; count_node++; node->parent = ch_l; ch_r->parent = ch_l; ch_l->left = node; ch_l->right = ch_r; ch_l->d_mode = SP; for( i = 0; i < (ch_r->num_csp); i++ ) { if( !is_in_list(ch_r->ch_sp[i], ch_l->ch_sp, ch_l->num_csp) ) { ch_l->ch_sp[ch_l->num_csp] = ch_r->ch_sp[i]; ch_l->num_csp = (ch_l->num_csp) + 1; } } strcpy(ch_l->name, "\0"); }
void ft_parse_init(TREE *wtree, const CHARSET_INFO *cs) { DBUG_ENTER("ft_parse_init"); if (!is_tree_inited(wtree)) init_tree(wtree,0,0,sizeof(FT_WORD),(qsort_cmp2)&FT_WORD_cmp,0,NULL, cs); DBUG_VOID_RETURN; }
void show_yearly_stats() { GtkWidget *window; GtkWidget *sw; if (yearly_tree) return; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); sw = gtk_scrolled_window_new (NULL, NULL); yearly_tree = gtk_tree_view_new (); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_window_set_default_size(GTK_WINDOW(window), 640, 480); gtk_window_set_title(GTK_WINDOW(window), _("Yearly Statistics")); gtk_container_set_border_width(GTK_CONTAINER(window), 5); gtk_window_set_resizable(GTK_WINDOW(window), TRUE); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN); gtk_container_add (GTK_CONTAINER (sw), yearly_tree); gtk_container_add (GTK_CONTAINER (window), sw); /* Display the yearly statistics on top level * Monthly statistics are available by expanding a year */ init_tree(); update_yearly_stats(); g_signal_connect (G_OBJECT (window), "key_press_event", G_CALLBACK (key_press_event), NULL); g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (stat_on_delete), NULL); gtk_widget_show_all(window); }
int main() { init_tree(); char cmd[16], args[3][16]; int n = 0, m; while (scanf("%s", cmd) == 1) { if (!strcmp(cmd, "insert")) { scanf("%s %s %d", args[0], args[1], &m); int pos = -1, x; if (!strcmp(args[0], "left")) { pos = 1; } else if (!strcmp(args[0], "right")) { pos = n+1; } else { sscanf(args[0], "%d", &x); pos = x; } Char c = {args[1][0], m}; insert(pos, c); n += m; } else { print_tree(); } } return 0; }
int main() { char ch,ch2; int eflag; printf("Binary Search Tree Start\n"); /* init tree */ //reserved :: init_tree(&tree); eflag = 1; while(1){ printf("\n1. insert\n"); printf("2. search\n"); printf("3. delete\n"); printf("4. view Tree\n"); printf("5. exit\n"); printf("------------------\n"); printf("command : "); ch = getchar(); ch2 = getchar(); printf("\n"); switch(ch){ case '1': case 'i': case 'I': insert(&tree); break; case '2': case 's': case 'S': search(&tree); break; case '3': case 'd': case 'D': delete(&tree); break; case '4': case 'v': case 'V': display(&tree); break; case '5': case 'e': case 'E': case 'q': case 'Q': printf("Terminated by user\n"); //reserved :: eflag = -1; break; default: break; } if( eflag != 1 ) break; } printf("Finished Program\n\n"); return 0; }
void init_string (tree_s *tree, log_s *log) { bind_tree_log(log, TREE_SLOT); init_tree(tree, &String_species, log->lg_sys, log, TREE_SLOT); add_slot_log(log, STRING_SLOT, String_redo); init_super_block(tree); }
int start_grammar(t_sh *sh) { if (init_tree(&(sh->tree), sh->lexer) == QUIT_RET) return (QUIT_RET); if (place_tree(&(sh->tree)) == QUIT_RET) return (QUIT_RET); return (EXIT_SUCCESS); }
static int vdi_tree(int argc, char **argv) { init_tree(); parse_vdi(print_vdi_tree, SD_INODE_HEADER_SIZE, NULL); dump_tree(); return EXIT_SUCCESS; }
void maria_ft_parse_init(TREE *wtree, CHARSET_INFO *cs) { DBUG_ENTER("maria_ft_parse_init"); if (!is_tree_inited(wtree)) init_tree(wtree,0,0,sizeof(FT_WORD),(qsort_cmp2)&FT_WORD_cmp, NULL, (void*) cs, MYF(0)); DBUG_VOID_RETURN; }
void init_ui(char *name) { init_curses(); init_tree(name); init_lines(); print_line(FILE(tree_root)->line); open_directory(tree_root); refresh_screen(); }
BiTreePtr create_tree(BiTreePtr *pt){ BiTreePtr new_T = NULL; init_tree(&new_T); if (pt != NULL) { *pt = new_T; } return new_T; }
info_s *alloc_info (unint name_len, tree_species_s *species, dev_s *dev) { info_s *info; FN; info = ezalloc(sizeof(info_s) + name_len); init_tree( &info->in_tree, species, dev); return info; }
struct BTreeNode *init_tree(size_t h) { if (h == 0ul) return NULL; struct BTreeNode *node; HANDLE_MALLOC(node, sizeof(struct BTreeNode)); /* node->value = rand_in_int_range(1, 2); */ node->value = 0; --h; node->l_child = init_tree(h); node->r_child = init_tree(h); return node; }
/*构造树*/ node * init_tree() { node *root=NULL; char ch; scanf("%c",&ch); getchar(); if(ch=='0') return NULL; else { root=(node*)malloc(1*sizeof(node)); root->ch=ch; root->lchild=NULL; root->rchild=NULL; root->lchild=init_tree(); root->rchild=init_tree(); } return root; }
void TreeTest(void) { Ihandle* dlg; init_tree(); /* Initializes IupTree */ init_dlg(); /* Initializes the dlg */ dlg = IupGetHandle("dlg"); /* Retrieves the dlg handle */ IupShowXY(dlg, IUP_CENTER, IUP_CENTER); /* Displays the dlg */ init_tree_nodes(); /* Initializes attributes, can be done here or anywhere */ }
void competition_sort(int a[], int len) { int i, j; int n; struct node *tree; n = get_count(len); creat_tree(&tree, n); init_tree(tree, a, n); }
int main(int argc, char const *argv[]) { node *root=init_tree(); pre_tree(root); printf("\n"); mid_tree(root); printf("\n"); last_tree(root); printf("\n"); return 0; }
int main(){ Tree * tree; /*Tree ADT - holds integer values in AVL tree being tested*/ int * entry; /*Temporary variable when adding to, removing from and searching tree*/ int * result; /*Result of search*/ int i; /*Controls loops*/ tree = init_tree(&compare, &compare, &destroy, &print, &collision); printf("Adding the numbers to the tree in an out of sequence order :\n"); for (i = 0; i < 12; i++){ entry = malloc(sizeof(int)); *entry = (3 * i) % 10; printf("%d, ", *entry); tree = add_to_tree(tree, entry); } putchar('\n'); printf("Repeated some entries to test collision resolution.\n"); printf("Tree after insertions.\n"); print_tree(tree); for (i = 0; i < 10; i = i + 3){ entry = malloc(sizeof(int)); *entry = i; remove_from_tree(tree, entry); free(entry); printf("%d is removed...\n", i); print_tree(tree); putchar('\n'); } printf("Testing search_tree_closest...\n"); printf("Searching for 3 (no longer in tree), should return 4.\n"); entry = malloc(sizeof(int)); *entry = 3; result = search_tree_closest(tree, entry); printf("Returned : %d\n", *result); free(entry); printf("Note : Because the search_tree_closest function works, \n"); printf("it follows that the search_tree function must also work.\n"); printf("In the context of only integers, this function doesn't \n"); printf("really make sense though.\n"); printf("Destroying tree...\n"); destroy_tree(tree); printf("\n\nAll tests passed.\n"); return 0; }
int main_test(void){ BiTree *T = NULL; init_tree(&T); process_input(T); build_tree(T); traverse_tree(T); return 0; }
static int add_node(struct _node* father, char letter){ if(father==NULL||letter=='\0') return EXIT_FAILURE; struct _node *node = init_tree(); struct _node *penultimate = father->last_son; node->c=letter; if(penultimate==NULL) father->first_son=node; else penultimate->brother=node; father->last_son=node; return EXIT_SUCCESS; }
void add_tree_after(t_tree *tree, int type, int *access) { t_tree *ptr; ptr = init_tree(type, access); if (tree->next != NULL) { ptr->next = tree->next; tree->next->prev = ptr; } tree->next = ptr; ptr->prev = tree; }
void swap_nodes(struct p_tree *a, struct p_tree *b) { struct p_tree *t = NULL; t = (struct p_tree *) ckalloc(sizeof(struct p_tree)); init_tree(t); assign_node(t, a, NO_DEALLOC); t->parent = a->parent; t->depth = a->depth; assign_node(a, b, NO_DEALLOC); assign_node(b, t, NO_DEALLOC); free(t); }
void main(int argc, char *argv[]) { size_t nitem = 0; char *tok; FILE *fp; char str[256]; struct wcount wc, *wcp; int i; if (argc < 2) { printf("\n Usage : wcount [filename]"); exit(1); } init_tree(&head); if ((fp = fopen(argv[1], "rt")) == NULL) { printf("\n Can't find that file."); exit(1); } fgets(str, 255, fp); while (!feof(fp)) { tok = strtok(str, delim); while (tok) { for (i = 0; i < strlen(tok); i++) tok[i] = tolower(tok[i]); strcpy(wc.word, tok); wcp = rbtr_search(&wc, head, &nitem, sizeof(wc), wcount_cmp); if (wcp == NULL) { wc.count = 1; rbtr_insert(&wc, head, &nitem, sizeof(wc), wcount_cmp); } else (wcp->count)++; tok = strtok(NULL, delim); } fgets(str, 256, fp); } printf("\n"); rbtr_sort(head->left, print_wcount); bioskey(0); printf("\n"); rbtr_list(head->left, print_wcount); bioskey(0); rbtr_draw(head->left, LINK|NODE|TAIL, make_str); rbtr_deleteall(head, &nitem); }
int main(int argc, char *argv[]){ element_type array[20]; element_type array1[20]; int i; BTREE T1 = init_tree(); BTREE T2 = init_tree(); BTREE T3 = NULL; for(i=0; i<20; i++){ array[i] = random(200); array1[i] = i; printf("%d ", array[i]); } printf("\n"); T1 = creat_tree(array, sizeof(array)/sizeof(array[0]), T1); T2 = creat_tree(array, 1, T2); preorder(T1); printf("\n"); preorder(T2); printf("\n"); if(contain_tree(T1, T2)) printf("T1 contains T2\n"); else printf("T1 doesn't contain T2\n"); free_tree(T1); free_tree(T2); return 0; }
int main() { int temp[20] = {12, 5, 9, 16,15,11}; int i = 0; TreeNode * treetemp = NULL; init_tree(); for(i = 0;i < 6; i++) { insert(temp[i]); } treetemp= find(20); pre_order(treetemp); printf(" \nnumber: %d \n",num); }
void main() { init_tree(); //sort_word_count(HEADER); printf("node left right parent\n"); show_tree(HEADER); /*x=del_node(x); if(x != NULL) printf("%s --%d\n",x->word,x->count); show_tree(HEADER); add_node("NAME"); show_tree(HEADER); */ }
struct tree *treemake(data_type type, union data_u data, struct tree *child, va_list args) { struct tree *root = malloc(sizeof(struct tree)); init_tree(root); root->type = type; root->data = data; while (child != NULL) { add_child(root, child); inc_refcount(child); child = va_arg(args, struct tree *); } return root; }
/* Initialize the C++ front end. This function is very sensitive to the exact order that things are done here. It would be nice if the initialization done by this routine were moved to its subroutines, and the ordering dependencies clarified and reduced. */ bool cxx_init (void) { location_t saved_loc; unsigned int i; static const enum tree_code stmt_codes[] = { CTOR_INITIALIZER, TRY_BLOCK, HANDLER, EH_SPEC_BLOCK, USING_STMT, TAG_DEFN, IF_STMT, CLEANUP_STMT, FOR_STMT, RANGE_FOR_STMT, WHILE_STMT, DO_STMT, BREAK_STMT, CONTINUE_STMT, SWITCH_STMT, EXPR_STMT }; memset (&statement_code_p, 0, sizeof (statement_code_p)); for (i = 0; i < ARRAY_SIZE (stmt_codes); i++) statement_code_p[stmt_codes[i]] = true; saved_loc = input_location; input_location = BUILTINS_LOCATION; init_reswords (); init_tree (); init_cp_semantics (); init_operators (); init_method (); init_error (); current_function_decl = NULL; class_type_node = ridpointers[(int) RID_CLASS]; cxx_init_decl_processing (); if (c_common_init () == false) { input_location = saved_loc; return false; } init_cp_pragma (); init_repo (); input_location = saved_loc; return true; }
void half_tree(int its) { struct tree tree; /* SDL_Surface *screen; */ init_tree(&tree); tree.iterations = its; tree.exp_size = 34 * 4; strncpy(tree.expansion, "(!(+++++++++!)----------)+++++++++" "(!(+++++++++!)----------)+++++++++" "(!(+++++++++!)----------)+++++++++" "(!(+++++++++!)----------)+++++++++", tree.exp_size); gen_branches(&tree); /* print_leaves(&tree); */ }