diff --git a/Trees/AVLTREE.C b/Trees/AVLTREE.C index 6ece137f..b09dc26f 100644 --- a/Trees/AVLTREE.C +++ b/Trees/AVLTREE.C @@ -1,6 +1,15 @@ /*Successful implementation of AVL tree with proper rotations Code done by Parshwa Shah */ +/*Update From Hari(username: Haricodezz) +clrscr() is not part of the standard C library and is not portable. + For cross-platform compatibility, consider using: + system("cls"); // for Windows + system("clear"); // for Unix-like systems + Alternatively, ANSI escape codes can be used for more control over console output. + + + */ #include #include #include @@ -25,13 +34,13 @@ int max1(int a,int b) { return (a>b)?a:b; } -struct node* new(int key) +struct node* New(int key) { struct node* node = (struct node*)malloc(sizeof(struct node)); node->key = key; node->left = NULL; node->right = NULL; - node->h= 1; // new node is initially added at leaf + node->h= 1; // New node is initially added at leaf return(node); } struct node *leftrot(struct node *x) @@ -70,7 +79,7 @@ int bal=0; if(ele==NULL) { //printf("Key=%d Balance factor=0\n",ele->key); -return new(ke); +return New(ke); } else if(ke>ele->key) { @@ -118,15 +127,15 @@ while(curr->left!=NULL) {curr=curr->left;} return curr; } -struct node* delete(struct node *root,int key) +struct node* Delete(struct node *root,int key) { int bal=0; if(root==NULL) {return root;} if(keykey) -{root->left=delete(root->left,key);} +{root->left=Delete(root->left,key);} else if(key>root->key) -{root->right=delete(root->right,key);} +{root->right=Delete(root->right,key);} else { if((root->left==NULL) || (root->right==NULL)) @@ -147,7 +156,7 @@ else { struct node *temp= inordersucc(root->right); root->key=temp->key; -root->right=delete(root->right,temp->key); +root->right=Delete(root->right,temp->key); } } @@ -189,10 +198,17 @@ inorder(root->left); printf("%d ",root->key); inorder(root->right); } -void main() +int main() { int key,m=0; -clrscr(); +// clrscr(); +// Replaced clrscr() with system-specific clear command for portability. +#ifdef _WIN32 + system("cls"); // Clear screen on Windows +#else + system("clear"); // Clear screen on Unix-like systems +#endif + do { printf("Enter the key to insert or 0 to quit\n"); @@ -224,11 +240,12 @@ scanf("%d",&key); if(key==0) break; printf("\n************************************\n\n"); -root=delete(root,key); +root=Delete(root,key); printf("\n************************************\n\n"); } while(key!=0); printf("Inorder traversal of tree : "); inorder(root); getch(); +return 0; } \ No newline at end of file