void main() { struct node *p; p=NULL; int ele,ch,key=0; while(!0) { system("cls"); printf("1. Insert At Front\n2. Insert to Left\n3. Delete Node\n4. Display\n5. Exit\n\nEnter Choice : "); scanf("%d",&ch); switch(ch) { case 1:printf("\nEnter Element To Insert : "); scanf("%d",&ele); p=addatbeg(p,ele); break; case 2:printf("\nEnter Element To Insert : "); scanf("%d",&ele); printf("\nEnter Key To Search On : "); scanf("%d",&key); p=addleft(p,ele,key); break; case 3:p=del(p); break; case 4:display(p); break; case 5:exit(0); break; default:printf("\nInvalid Selection"); } } }
static void rearrange (BTree* a, int pos) { if (pos==a->n) /* convert child index into key index */ pos--; BTree* left = a->p[pos]; BTree* right = a->p[pos+1]; if (left->n + right->n + 1 >= a->ordem) { /* redistribute */ while (underflow( left )) { addright(left, left->n, a->k[pos], right->p[0]); a->k[pos] = right->k[0]; delleft(right, 0); } while (underflow(right)) { addleft(right, 0, a->k[pos],left->p[left->n]); a->k[pos] = left->k[left->n-1]; delright(left, left->n-1); } } else { /* concatenate */ addright(left ,left->n,a->k[pos],right->p[0]); for (int i=0; i<right->n; ++i) addright(left, left->n, right->k[i], right->p[i+1]); free(right); delright(a, pos); } }
void listput(double val, int k) { if (val <= now->v) { while (val <= now->v && now != first) now = now->l; if (now == first && val <= now->v) addfirst(val,k); else addright(val,k); } else { while (val > now->v && now != last) now = now->r; if (now == last && val > now->v) addlast(val,k); else addleft (val, k); } } // listput