/* create the fixed tables in C initialization syntax */ void main(void) { int r; uInt bl, bd; const inflate_huft *tl, *td; z_stream z; z.zalloc = zcalloc; z.opaque = (voidpf)0; z.zfree = zcfree; r = inflate_trees_fixed(&bl, &bd, &tl, &td, &z); if (r) { fprintf(stderr, "inflate_trees_fixed error %d\n", r); return; } puts("/* inffixed.h -- table for decoding fixed codes"); puts(" * Generated automatically by the maketree.c program"); puts(" */"); puts(""); puts("/* WARNING: this file should *not* be used by applications. It is"); puts(" part of the implementation of the compression library and is"); puts(" subject to change. Applications should only use zlib.h."); puts(" */"); puts(""); printf("local uInt fixed_bl = %d;\n", bl); printf("local uInt fixed_bd = %d;\n", bd); printf("local const inflate_huft fixed_tl[] = {"); maketree(bl, tl); puts(" };"); printf("local const inflate_huft fixed_td[] = {"); maketree(bd, td); puts(" };"); }
int maketree(int x,int root) { int i,j; //printf("maketree begin\n"); rroot=root; if ((bope[x]=='+')||(bope[x]=='-')) { //printf("find %c\n",bope[x]); fa[root]=x; lson[x]=root; rson[x]=x+1; rroot=x; if (x+2<=k) { //printf("do make\n"); //printf("x=%d,root=%d!",x,root); maketree(x+2,x); } } else { fa[x]=root; lson[x]=rson[root]; rson[x]=x-1; rson[root]=x; if (x+2<=k) maketree(x+2,root); } return 0; }
void maketree(int n,int l,int h) { if(l==h) b[n]=(long long )a[l]; else { maketree(2*n,l,(l+h)/2); maketree(2*n+1,(l+h)/2+1,h); b[n]=b[2*n]+b[2*n+1]; } }
void maketree(int arr[], int head, int tail, Node** dest) { if (head > tail) { *dest = NULL; return; } int mid = (head+tail)/2; (*dest) = malloc(sizeof(Node)); (*dest)->val = arr[mid]; maketree(arr, head, mid-1, &((*dest)->left)); maketree(arr, mid+1, tail, &((*dest)->right)); }
/* * make query tree from plain view of query */ static NODE * maketree(QueryItem *in) { NODE *node = (NODE *) palloc(sizeof(NODE)); node->valnode = in; node->right = node->left = NULL; if (in->type == QI_OPR) { node->right = maketree(in + 1); if (in->qoperator.oper != OP_NOT) node->left = maketree(in + in->qoperator.left); } return node; }
/* * make query tree from plain view of query */ static NODE * maketree(ITEM * in) { NODE *node = (NODE *) palloc(sizeof(NODE)); node->valnode = in; node->right = node->left = NULL; if (in->type == OPR) { node->right = maketree(in + 1); if (in->val != (int4) '!') node->left = maketree(in + in->left); } return node; }
/* * GTK1: build the tree. */ void maketree(GtkCTreeNode *subtree, struct tree *t) { GtkCTreeNode *sibling=NULL, *sibling_test; struct tree *t2; if(!GLOBALS->hier_grouping) { t2=t; while(t2) { sibling_test=maketree_nodes(subtree, t2, sibling, MAKETREE_FLATTEN); sibling=sibling_test?sibling_test:sibling; t2=t2->next; } } else { t2=t; while(t2) { if(!t2->child) { sibling_test=maketree_nodes(subtree, t2, sibling, MAKETREE_LEAF); if(sibling_test) { maketree(sibling=sibling_test, t2->child); } } t2=t2->next; } t2=t; while(t2) { if(t2->child) { sibling_test=maketree_nodes(subtree, t2, sibling, MAKETREE_NODE); if(sibling_test) { maketree(sibling=sibling_test, t2->child); } } t2=t2->next; } } }
QueryItem * clean_NOT(QueryItem *ptr, int *len) { NODE *root = maketree(ptr); return plaintree(clean_NOT_intree(root), len); }
void inclui_no(pont &inicio) //versao nao recursiva {clrscr(); pont pai, filho; int number; printf("Digite valor: "); scanf("%i", &number); if (inicio == 0) //arvore vazia { inicio = maketree(number); } else {pai = filho = inicio; while (filho != NULL) { pai = filho; //porque filho sera alterado e preciso deste end //que serah pai do novo filho if (number > (pai->valor) ) filho = filho->dir; else filho = filho->esq; } if (number > (pai->valor) ) setdir(pai, number); else setesq(pai, number); } }
void insert(NODEPTR *tree){ NODEPTR p,q; int key; printf("\nEnter the keys"); scanf("%d",&key); while(key != EOF){ p=NULL;q=*tree; while(q!=NULL){ p=q; if(key<=p->key) q=p->left; else q=p->right; }/*End of inner while*/ if(p==NULL){ *tree=maketree(key); }else if(key<=p->key){ setleft(p,key); } else setright(p,key); scanf("%d",&key); }/*end of outer while*/ }/*end of insert function*/
ITEM * clean_NOT(ITEM * ptr, int4 *len) { NODE *root = maketree(ptr); return plaintree(clean_NOT_intree(root), len); }
/* * Remove QI_VALSTOP (stopword) nodes from TSQuery. */ TSQuery cleanup_tsquery_stopwords(TSQuery in) { int32 len, lenstr, commonlen, i; NODE *root; int ladd, radd; TSQuery out; QueryItem *items; char *operands; if (in->size == 0) return in; /* eliminate stop words */ root = clean_stopword_intree(maketree(GETQUERY(in)), &ladd, &radd); if (root == NULL) { ereport(NOTICE, (errmsg("text-search query contains only stop words or doesn't contain lexemes, ignored"))); out = palloc(HDRSIZETQ); out->size = 0; SET_VARSIZE(out, HDRSIZETQ); return out; } /* * Build TSQuery from plain view */ lenstr = calcstrlen(root); items = plaintree(root, &len); commonlen = COMPUTESIZE(len, lenstr); out = palloc(commonlen); SET_VARSIZE(out, commonlen); out->size = len; memcpy(GETQUERY(out), items, len * sizeof(QueryItem)); items = GETQUERY(out); operands = GETOPERAND(out); for (i = 0; i < out->size; i++) { QueryOperand *op = (QueryOperand *) &items[i]; if (op->type != QI_VAL) continue; memcpy(operands, GETOPERAND(in) + op->distance, op->length); operands[op->length] = '\0'; op->distance = operands - GETOPERAND(out); operands += op->length + 1; } return out; }
int main() { FILE *fp=fopen("D:\\word4.rar","rb"); printf("inti()\n"); unsigned long freq[MAX]; getfreq(fp,freq); init(freq); printf("maketree\n"); rewind(fp); maketree(); printf("filetobit\n"); // long masd=0; // for(int i=0;i<MAX;i++){ // printf("%ld\t%d\n",order[i]->freq,order[i]->ch); // masd+=order[i]->freq*order[i]->getlen(); // } //printf("%ld\n",masd); unsigned long n; unsigned char *a=codetobit(fp,&n); printf("%ld\n",n); fclose(fp); fp=fopen("test.huf","wb"); fwrite(a,n,1,fp); fclose(fp); }
int main(int argc, char* argv[]) { int labels[16]; int i = 0; for(i = 0; i < 16; i++) { labels[i] = i; } void* t = maketree(&labels[8], maketree(&labels[3], leaf(&labels[1]), maketree(&labels[6], emptytree(), leaf(&labels[7]))), maketree(&labels[11], maketree(&labels[9], emptytree(), leaf(&labels[10])), maketree(&labels[14], leaf(&labels[12]), leaf(&labels[15])))); printf("struct node size: %lu\n", sizeof(struct node)); printf("tree pointer: %p\n", t); printf("size(): %d\n", size(t)); printf("numleaves(): %d\n", numleaves(t)); printf("equalbintree(): %d\n", equalbintree(t, t)); return 0; }
/* * make query tree from plain view of query */ static NODE * maketree(QueryItem *in) { NODE *node = (NODE *) palloc(sizeof(NODE)); /* since this function recurses, it could be driven to stack overflow. */ check_stack_depth(); node->valnode = in; node->right = node->left = NULL; if (in->type == QI_OPR) { node->right = maketree(in + 1); if (in->qoperator.oper != OP_NOT) node->left = maketree(in + in->qoperator.left); } return node; }
void setright(NODEPTR p,int key){ if(p==NULL) printf("void insertion"); else if(p->right != NULL) printf("invalid insertion"); else p->right=maketree(key); }
void maketree(int curr ,int low ,int high ,int n,int h) { if(low==high){ tree[curr]=a[low]; return; } int mid=low+(high-low)/2; maketree(2*curr+1,low, mid,n,h+1); maketree(2*curr+2,mid+1, high,n,h+1); if((n-h)%2==1){ tree[curr]=tree[2*curr+1]|tree[2*curr+2]; } else { tree[curr]=tree[2*curr+1]^tree[2*curr+2]; } // printf("%d %d\n",curr,tree[curr]); }
int maketree (void) { HANDLE hdir; int slen, dlen, rv = 0; DWORD br; UINT bw; slen = strlen(SrcPath); dlen = strlen(DstPath); sprintf(&SrcPath[slen], "/*"); hdir = FindFirstFile(SrcPath, &Fd); /* Open directory */ if (hdir == INVALID_HANDLE_VALUE) { printf("Failed to open directory.\n"); } else { for (;;) { sprintf(&SrcPath[slen], "/%s", Fd.cFileName); sprintf(&DstPath[dlen], "/%s", Fd.cFileName); if (Fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { /* The item is a directory */ if (strcmp(Fd.cFileName, ".") && strcmp(Fd.cFileName, "..")) { if (f_mkdir(DstPath)) { /* Create destination directory */ printf("Failed to create directory.\n"); break; } if (!maketree()) break; /* Enter the directory */ Dirs++; } } else { /* The item is a file */ printf("%s\n", SrcPath); if ((SrcFile = CreateFile(SrcPath, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) { /* Open source file */ printf("Failed to open source file.\n"); break; } if (f_open(&DstFile, DstPath, FA_CREATE_ALWAYS | FA_WRITE)) { /* Create destination file */ printf("Failed to create destination file.\n"); break; } do { /* Copy source file to destination file */ ReadFile(SrcFile, Buff, sizeof Buff, &br, 0); if (br == 0) break; f_write(&DstFile, Buff, (UINT)br, &bw); } while (br == bw); CloseHandle(SrcFile); f_close(&DstFile); if (br && br != bw) { printf("Failed to write file.\n"); break; } Files++; } if (!FindNextFile(hdir, &Fd)) { rv = 1; break; } } FindClose(hdir); } SrcPath[slen] = 0; DstPath[dlen] = 0; return rv; }
kdtree::kdtree(vector<particle*> & plist) { if (plist.size()) { root = new kdnode(); maketree(root, plist, true); } else root = NULL; }
int main(int argc, Char *argv[]) { int i; #ifdef MAC argc = 1; /* macsetup("Fitch",""); */ argv[0]="Fitch"; #endif #ifdef WIN32 phySetConsoleAttributes(); phyClearScreen(); #endif strcpy(progname,argv[0]); openfile(&infile,INFILE,"input file","r",argv[0],infilename); openfile(&outfile,OUTFILE,"output file","w",argv[0],outfilename); ibmpc = IBMCRT; ansi = ANSICRT; mulsets = false; datasets = 1; firstset = true; doinit(); if (trout) openfile(&outtree,OUTTREE,"output tree file","w",argv[0],outtreename); for (i=0;i<spp;++i){ enterorder[i]=0;} for (ith = 1; ith <= datasets; ith++) { if (datasets > 1) { fprintf(outfile, "Data set # %ld:\n\n",ith); if (progress) printf("\nData set # %ld:\n\n",ith); } fitch_getinput(); for (jumb = 1; jumb <= njumble; jumb++) maketree(); firstset = false; if (eoln(infile)) { fscanf(infile, "%*[^\n]"); getc(infile); } } if (trout) FClose(outtree); FClose(outfile); FClose(infile); #ifdef MAC fixmacfile(outfilename); fixmacfile(outtreename); #endif printf("Done.\n\n"); #ifdef WIN32 phyRestoreConsoleAttributes(); #endif return 0; }
int tree() { struct node* root; int num,delet,a; root=(struct node*)malloc(sizeof(struct node)); int choice; while(1) { printf("***************************************TREE MODULE*******************************************************"); printf("Enter your choice\n1 for INSERTION\n2 for INORDER TRAVERSAL\n3 for PREORDER TRAVERSAL\n4 for POSTORDER TRAVERSAL\n5 for Deletion\n6 for TBT OPERATIONS \n7 for AVL OPERATIONS\n8 to Exit\n"); scanf("%d",&choice); switch(choice) { case 1: printf("Enter the value you want to insert\n"); scanf("%d",&num); maketree(num,root); break; case 2: printf("\nInorder:"); inorder(root); break; case 3: printf("\nPreorder:"); preorder(root); break; case 4: printf("\nPostorder:"); postorder(root); break; case 5: printf("Enter the value you want to delete"); scanf("%d",&delet); delete(delet,root); break; case 6: a=tbt(); break; case 7: a=avl1(); break; case 8: exit(0); } } return 0; }
string Huffman::encode(string s) { map<char, int> freq = calcfreq(s); map<char, node*> position; node *p; foreach(v, freq) { node *p = maketree(v->second); position[v->first] = p; rootnodes.push(p); }
int main(int argc, Char *argv[]) { /* main program */ long i; #ifdef MAC argc = 1; /* macsetup("Contml",""); */ argv[0] = "Contml"; #endif init(argc, argv); emboss_getoptions("fcontml", argc, argv); progname = argv[0]; ibmpc = IBMCRT; ansi = ANSICRT; firstset = true; doinit(); for (ith = 1; ith <= datasets; ith++) { getinput(); if (ith == 1) firstset = false; if (datasets > 1) { fprintf(outfile, "Data set # %ld:\n\n", ith); if (progress) printf("\nData set # %ld:\n", ith); } for (jumb = 1; jumb <= njumble; jumb++) maketree(); if (usertree) for (i = 0; i < MAXSHIMOTREES; i++) free(l0gf[i]); } FClose(outfile); FClose(outtree); #ifdef MAC fixmacfile(outfilename); fixmacfile(outtreename); #endif printf("\nDone.\n\n"); #ifdef WIN32 phyRestoreConsoleAttributes(); #endif ajPhyloFreqDel(&phylofreq); ajPhyloTreeDelarray(&phylotrees); ajFileClose(&embossoutfile); ajFileClose(&embossouttree); embExit(); return 0; }
int main() { Node* root; Node* test; int arr[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; maketree(arr, 0, sizeof(arr)/sizeof(int)-1, &root); test = root->left->right->right; printf("%d is looking for %d\n", test->val,inorder_succ(root, test)); return 0; }
int main(){ int n,m,i,j,p=1,x,y,o=0; scanf("%d %d",&o,&m); for(i=0;i<o;i++)p*=2; n=p; for(i=0;i<n;i++)scanf("%d",&a[i]); maketree(0,0,n-1,o,0); for(i=0;i<m;i++){ scanf("%d %d",&x,&y); update(0,0,n-1,o,0,x-1,y); printf("%d\n",tree[0]); } }
//function to generate permuted array and make the corresponding trees simultaneously with help from above function void permute(int *a, int i, int n) { int j; if(i==n) { maketree(a,n); } else { for (j = i; j <= n; j++) { swap((a+i), (a+j)); permute(a, i+1, n); swap((a+i), (a+j)); //backtrack } } }
void addword(node *tree,char word[],char meaning[]) { node *p,*q; p=q=tree; while(strcmp(word,p->word)!=0 && p!=NULL) { q=p; if(strcmp(word,p->word)<0) { p=p->left; } else { p=p->right; } } if(strcmp(word,q->word)==0) { printf("This word already exists..."); delay(1000); } else{ if(strcmp(word,q->word)<0) { q->left=maketree(word,meaning); } else { q->right=maketree(word,meaning); } } }
int main(int argc, Char *argv[]) { /* main program */ long i; #ifdef MAC argc = 1; /* macsetup("Contml",""); */ argv[0] = "Contml"; #endif init(argc, argv); progname = argv[0]; openfile(&infile,INFILE,"input file", "r",argv[0],infilename); openfile(&outfile,OUTFILE,"output file", "w",argv[0],outfilename); ibmpc = IBMCRT; ansi = ANSICRT; mulsets = false; firstset = true; datasets = 1; doinit(); if (trout) openfile(&outtree,OUTTREE,"output tree file", "w",argv[0],outtreename); for (ith = 1; ith <= datasets; ith++) { getinput(); if (ith == 1) firstset = false; if (datasets > 1) { fprintf(outfile, "Data set # %ld:\n\n", ith); if (progress) printf("\nData set # %ld:\n", ith); } for (jumb = 1; jumb <= njumble; jumb++) maketree(); if (usertree) for (i = 0; i < MAXSHIMOTREES; i++) free(l0gf[i]); } FClose(outfile); FClose(outtree); FClose(infile); #ifdef MAC fixmacfile(outfilename); fixmacfile(outtreename); #endif printf("\nDone.\n\n"); #ifdef WIN32 phyRestoreConsoleAttributes(); #endif return 0; }
main() { int i,j,path[10],wt_tree,count; struct edge tree[10]; create_graph(); printf("\n adjacency matrix\n"); display(); count=maketree(tree,&wt_tree); printf("\n weight of spanning tree is : %d \t\n",wt_tree); printf("\n edges in spanning tree\n"); for(i=1;i<n;i++) { printf( " %d -> ",tree[i].u); printf("%d\n",tree[i].v); } }
int main(int argc, Char *argv[]) { /* main program */ #ifdef MAC argc = 1; /* macsetup("Neighbor",""); */ argv[0] = "Neighbor"; #endif #ifdef WIN32 phySetConsoleAttributes(); phyClearScreen(); #endif openfile(&infile,INFILE,"input file", "r",argv[0],infilename); openfile(&outfile,OUTFILE,"output file", "w",argv[0],outfilename); ibmpc = IBMCRT; ansi = ANSICRT; mulsets = false; datasets = 1; doinit(); if (trout) openfile(&outtree,OUTTREE,"output tree file", "w",argv[0],outtreename); ith = 1; while (ith <= datasets) { if (datasets > 1) { fprintf(outfile, "Data set # %ld:\n",ith); if (progress) printf("Data set # %ld:\n",ith); } getinput(); maketree(); if (eoln(infile)) { fscanf(infile, "%*[^\n]"); getc(infile); } ith++; } FClose(infile); FClose(outfile); FClose(outtree); #ifdef MAC fixmacfile(outfilename); fixmacfile(outtreename); #endif printf("Done.\n\n"); #ifdef WIN32 phyRestoreConsoleAttributes(); #endif return 0; }