nguyentruong98

Untitled

Nov 10th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. typedef struct Node
  5. {
  6.       char Name[80], Phone[80], Email[80];
  7.       struct Node* leftChild;
  8.       struct Node* rightChild;
  9.       struct Node* parent;
  10. }Node;
  11. Node* root;
  12. Node* makeNode(char *s1, char* s2, char* s3)
  13. {
  14.       Node*p = (Node*)malloc(sizeof(Node));
  15.       strcpy(p->Name,s1);
  16.       strcpy(p->Phone,s2);
  17.       strcpy(p->Email,s3);
  18.       p->parent = NULL;
  19.       p->leftChild = NULL;
  20.       p->rightChild = NULL;
  21.       return p;
  22. }
  23. void addNode(Node*p)
  24. {
  25.       if(root == NULL)
  26.       {
  27.             root = p;
  28.             return;
  29.       }
  30.       Node*q = root;
  31.       int cmp;
  32.       while(1)
  33.       {
  34.             if(q == NULL)
  35.             {
  36.                   q = p;
  37.                   return;
  38.             }
  39.             cmp = strcmp(q->Name,p->Name)
  40.             switch(cmp)
  41.             {
  42.                   case 0:
  43.                   return;
  44.                   case -1:
  45.                   q = q->rightChild;
  46.                   break;
  47.                   case 1:
  48.                   q = q->leftChild;
  49.                   break;
  50.             }
  51.       }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment