Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct node* Insert (struct node **,char *N,int I);
- void Print(struct node **);
- struct node
- {
- char name[50];int id;struct node *right;struct node *left;
- }*root;
- int main()
- {
- root=NULL;
- int C;int id_temp;char name_temp[50];
- printf("\n************************************\nWelcome to Students data Organizer !\n************************************\n");
- here:
- printf("\nChoices :\n[1] Browse for a file \n[2] Insert a student Entry \n[3] Search for a student \n[4] Delete a student \n[5] Display Student List\nEnter 0 to reprint the list\n");
- here1:
- printf("\n\nChoice [] :");
- scanf("%d",&C);
- switch(C)
- {
- case 0:system("clear");goto here;break;
- case 1:break;
- case 2:
- system("clear");printf("\nInsertion \n*********");
- printf("\nStudent's name :");getchar();
- fgets(name_temp,sizeof(name_temp)-1,stdin);
- name_temp[strlen(name_temp)-1]='\0';
- printf("\nStudent's ID :");scanf("%d",&id_temp);
- Insert(&root,name_temp,id_temp);printf("Added Successfully !\n");goto here1;
- break;
- case 3:break;
- default :printf("\nWrong choice ! try again.\n");
- goto here;
- break;
- case 5:
- system("clear");printf("Display \n*********\n");
- Print(&root);goto here1;break;
- }
- return 0;
- }
- struct node *create_node(char *N,int I)
- {
- struct node *temp=(struct node*)malloc(sizeof(struct node));
- strcpy(temp->name,N);temp->id=I;
- temp->left=NULL;
- temp->right=NULL;
- return temp;
- };
- struct node* Insert(struct node** temp,char *N,int I)
- {
- if (!(*temp)){*temp=create_node(N,I);}
- else if ((*temp)->id >= I) (*temp)->left=Insert(&(*temp)->left,N,I);
- else (*temp)->right=Insert(&(*temp)->right,N,I);
- return *temp;
- }
- void Print(struct node **temp)
- {
- if (*temp)
- {
- printf("\n%s\t=>\t%d\n",(*temp)->name,(*temp)->id);
- Print(&(*temp)->left);Print(&(*temp)->right);
- }
- // else printf("List is empty !");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement