Git Product home page Git Product logo

being-coder's Introduction

struct NODE { int key; struct NODE *left; struct NODE *right; struct NODE *parent; };

typedef struct NODE node;

void rebuild(node *v,int s); int store(node *v,int A[],int idx); void destroy(node *t); int postorder(node *t,int Size); void inorder(node *t); int size(node *t); node *create(int A[],int left,int right,int median); node *insertKey(node *t,int Key,int n,int m); int height(node *t);

int main() { node *t; int nsml,Key,n,m,i,h=0; t=(node *)malloc(sizeof(node)); t->left=NULL; t->right=NULL; t->parent=NULL; printf("nsml = "); scanf("%d",&nsml); scanf("%d",&Key); t->key=Key; n=1; m=1; printf("Height = %d :",h); printf("\t%d\n",t->key); for(i=1;i<nsml;i++) { scanf("%d",&Key); t = insertKey(t,Key,n,m); h=height(t); printf("Height = %d",h); n++; if(m<n) m=n; inorder(t); } }

int size(node *t) { int Size=0; node *p; p=t; Size = postorder(p,Size); return Size; }

void inorder(node *t) //inorder traversal { node *p; p=t; if(p->left!=NULL) inorder(p->left); printf("%d ",p->key); if(p->right!=NULL) inorder(p->right);

}

int postorder(node *t,int Size) { node *p; p=t; if(p->left!=NULL) Size = postorder(p->left,Size); if(p->right!=NULL) Size = postorder(p->right,Size); Size++; return Size; }

void destroy(node *t) { if(t->left!=NULL) destroy(t->left); if(t->right!=NULL) destroy(t->right); free(t); }

int store(node *v,int A[],int idx) { if(v->left!=NULL) idx = store(v->left,A,idx); A[idx]=v->key; idx++; if(v->right!=NULL) idx =store(v->right,A,idx); return idx; }

int height(node *t) { int h1,h2; h1=h2=0; h1=height(t->left); h2=height(t->right); if(h1>h2) return h1; else return h2; }

void rebuild(node *v,int s) { int A[s],a; node *reference; store(v,A,0); reference=v->parent; if(reference->key>v->key) a=1; else a=2; destroy(v); if(a==1) reference->left=create(A,0,s-1,s/2); else reference->right=create(A,0,s-1,s/2); }

node *create(int A[],int left,int right,int median) { node *p; p=(node *)malloc(sizeof(node)); p->key=A[median]; p->left = create(A,left,median-1,(median+left)/2); p->right = create(A,median+1,right,(right+median)/2+1); return p; }

node *insertKey(node *t,int Key,int n,int m) { int depth=0; node *p,*q,*k; q=t; while(q!=NULL) { if(Keykey) { if(q->left==NULL) { p = (node *)malloc(sizeof(node)); p->left=NULL; p->right=NULL; p->parent = q; p->key=Key; q->left=p; depth++; q=p->left; k=p; } else { k=q; q=q->left; depth++; } } else if(Key>q->key) { if(q->right==NULL) { p = (node *)malloc(sizeof(node)); p->left=NULL; p->right=NULL; p->parent = q; p->key=Key; q->right=p; depth++; q=p->right; k=p; } else { k=q; q=q->right; depth++; } } else break; } if(depth<=1+ceil(log((double)n)/log(3/2))) { return t; } else while(k!=NULL) { if(size(k)>=(2/3)*size(k->left)&&size(k)>=(2/3)*size(k->right)) { rebuild(k,size(k)); break; } else k=k->parent; } return t;

# Added more code at the main repo

}

int a11, b11;

being-coder's People

Contributors

bhanuprakash-iitkgp avatar bhanu77prakash avatar suddu22 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.