AVLEXP
AVLEXP
h>
#include <stdlib.h>
FILE *fp;
char file[30];
void main() {
int n, x;
char str[30];
node *root = NULL;
char ch, ch1;
fp = fopen(file, "r");
while (fscanf(fp, "%s", str) != EOF) {
printf("%s", str);
root=insert(root,atoi(str));
}
fclose(fp);
do {
printf("\nSelect the Options:");
printf("\n1. Inorder");
printf("\n2. Delete");
printf("\n3. Exit:\n");
scanf("%d", &n);
switch (n) {
case 1:
printf("\nDo you want to store inorder data into file? (y/n): ");
scanf(" %c", &ch1);
if (ch1 == 'y') {
printf("\nEnter file name to store inorder info: ");
scanf("%s", file);
fp = fopen(file, "w");
inorder(root);
fclose(fp);
} else {
printf("\nOk....");
inorder(root);
}
break;
case 2:
printf("\nEnter an element to delete: ");
scanf("%d", &x);
root = delete(root, x);
printf("\nInorder traversal after deletion:\n");
inorder(root);
break;
case 3:
exit(0);
break;
default:
printf("\nWrong choice.");
break;
}
getch();
}