Advertisement
redsees

Untitled

May 1st, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct node*  Insert (struct node **,char *N,int I);
  6. void Print(struct node **);
  7.  
  8. struct node
  9. {
  10.     char name[50];int id;struct node *right;struct node *left;
  11. }*root;
  12.  
  13. int main()
  14. {
  15.     root=NULL;
  16.     int C;int id_temp;char name_temp[50];
  17.     printf("\n************************************\nWelcome to Students data Organizer !\n************************************\n");
  18.     here:
  19.     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");
  20.     here1:
  21.     printf("\n\nChoice [] :");
  22.     scanf("%d",&C);
  23.     switch(C)
  24.     {
  25.         case 0:system("clear");goto here;break;
  26.         case 1:break;
  27.         case 2:
  28.             system("clear");printf("\nInsertion \n*********");
  29.             printf("\nStudent's name :");getchar();
  30.             fgets(name_temp,sizeof(name_temp)-1,stdin);
  31.             name_temp[strlen(name_temp)-1]='\0';
  32.             printf("\nStudent's ID :");scanf("%d",&id_temp);
  33.             Insert(&root,name_temp,id_temp);printf("Added Successfully !\n");goto here1;
  34.             break;
  35.             case 3:break;
  36.             default :printf("\nWrong choice ! try again.\n");
  37.             goto here;
  38.             break;
  39.             case 5:
  40.                 system("clear");printf("Display \n*********\n");
  41.                 Print(&root);goto here1;break;
  42.     }
  43.     return 0;
  44. }
  45.  
  46. struct node *create_node(char *N,int I)
  47. {
  48.     struct node *temp=(struct node*)malloc(sizeof(struct node));
  49.     strcpy(temp->name,N);temp->id=I;
  50.     temp->left=NULL;
  51.     temp->right=NULL;
  52.     return temp;
  53. };
  54.  
  55. struct node* Insert(struct node** temp,char *N,int I)
  56. {
  57.     if (!(*temp)){*temp=create_node(N,I);}
  58.     else if ((*temp)->id >= I) (*temp)->left=Insert(&(*temp)->left,N,I);
  59.     else (*temp)->right=Insert(&(*temp)->right,N,I);
  60.     return *temp;
  61. }
  62.  
  63. void Print(struct node **temp)
  64. {
  65.     if (*temp)
  66.     {
  67.         printf("\n%s\t=>\t%d\n",(*temp)->name,(*temp)->id);
  68.         Print(&(*temp)->left);Print(&(*temp)->right);
  69.     }
  70.    // else printf("List is empty !");
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement