From 43da8a9b1e08a1a5850fd0d3d84ab8a016b806c7 Mon Sep 17 00:00:00 2001 From: Hari Prakash Date: Fri, 27 Jun 2025 19:04:33 +0530 Subject: [PATCH 1/2] clrscr() is not part of the standard C library and is not portable, so Upadted with cross-platform compatibility --- Trees/AVLTREE.C | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Trees/AVLTREE.C b/Trees/AVLTREE.C index 6ece137f..a082ca15 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 @@ -192,7 +201,14 @@ inorder(root->right); void 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"); From e27f801459538b55956f8a5f39da0d66c1c57079 Mon Sep 17 00:00:00 2001 From: Hari Prakash Date: Fri, 27 Jun 2025 19:12:12 +0530 Subject: [PATCH 2/2] clrscr() is not part of the standard C library and is not portable,so updated with cross-platform compatibility --- Trees/AVLTREE.C | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Trees/AVLTREE.C b/Trees/AVLTREE.C index a082ca15..b09dc26f 100644 --- a/Trees/AVLTREE.C +++ b/Trees/AVLTREE.C @@ -34,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) @@ -79,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) { @@ -127,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)) @@ -156,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); } } @@ -198,7 +198,7 @@ inorder(root->left); printf("%d ",root->key); inorder(root->right); } -void main() +int main() { int key,m=0; // clrscr(); @@ -240,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