daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Jan 19th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <time.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <Windows.h>
  6.  
  7. #define Name_Length 30
  8. #define Phone_Num_Length 20
  9.  
  10. double PCFreq = 0.0;
  11. __int64 CounterStart = 0;
  12.  
  13. typedef struct Binary_T
  14. {
  15.     char name[Name_Length];
  16.     char phone_Num[Phone_Num_Length];
  17.     struct Binary_T *Left_Child;
  18.     struct Binary_T *Right_Child;
  19. } BiT_Node;
  20. BiT_Node *Make_Tree(char name_data[], char ph_num_data[])
  21. {
  22.     BiT_Node *Root = (BiT_Node *)malloc(sizeof(BiT_Node));
  23.     strcpy(Root->name, name_data);
  24.     strcpy(Root->phone_Num, ph_num_data);
  25.     Root->Left_Child = NULL;
  26.     Root->Right_Child = NULL;
  27.     return Root;
  28. }
  29. BiT_Node *Add_BiT_Node_Recursion(BiT_Node *Root, char name_data[], char ph_num_data[])
  30. {
  31.     if (Root == NULL)
  32.         Root = Make_Tree(name_data, ph_num_data);
  33.     else if (strcmp(name_data, Root->name) <= 0)
  34.         Root->Left_Child = Add_BiT_Node_Recursion(Root->Left_Child, name_data, ph_num_data);
  35.     else
  36.         Root->Right_Child = Add_BiT_Node_Recursion(Root->Right_Child, name_data, ph_num_data);
  37.     return Root;
  38. }
  39. BiT_Node *Search_No_Recursion(BiT_Node *Root, BiT_Node *SearchData)
  40. {
  41.     if (Root->name == NULL)
  42.     {
  43.         printf("No found for empty database\n");
  44.         return NULL;
  45.     }
  46.     else
  47.     {
  48.         BiT_Node * prev = NULL;
  49.         BiT_Node * current = Root;
  50.         while (current != NULL)
  51.         {
  52.             prev = current;
  53.             if (strcmp(SearchData->name, current->name) > 0)
  54.                 current = current->Right_Child;
  55.             else if (strcmp(SearchData->name, current->name) < 0)
  56.                 current = current->Left_Child;
  57.             else
  58.                 return current;
  59.         }
  60.         printf("Data No found\n");
  61.         return NULL;
  62.     }
  63. }
  64.  
  65. void StartCounter()
  66. {
  67.     LARGE_INTEGER li;
  68.     if (!QueryPerformanceFrequency(&li))
  69.         printf("QueryPerformanceFrequency failed!\n");
  70.     PCFreq = double(li.QuadPart) / 1000.0;
  71.     QueryPerformanceCounter(&li);
  72.     CounterStart = li.QuadPart;
  73. }
  74. double GetCounter()
  75. {
  76.     LARGE_INTEGER li;
  77.     QueryPerformanceCounter(&li);
  78.     return double(li.QuadPart - CounterStart) / PCFreq;
  79. }
  80. int main()
  81. {
  82.  
  83.     BiT_Node *Expo = NULL;
  84.     printf("Input name of  file:");
  85.     FILE *file; char file_name[256]; scanf("%s", file_name);
  86.  
  87.     char name_data[Name_Length]; char ph_num_data[Phone_Num_Length];
  88.     file = fopen(file_name, "r");
  89.     if (file == NULL)
  90.         printf("Can not open this file\nPlease check your filename\n");
  91.     while ((fscanf(file, "%s%s", name_data, ph_num_data) != EOF))
  92.     {
  93.         Expo = Add_BiT_Node_Recursion(Expo, name_data, ph_num_data);
  94.     }
  95.     fclose(file);
  96.     printf("INPUT YOUR DATA for searching:\n");
  97.     char R_Search_Name[Name_Length];
  98.     char R_Search_PhNum[Phone_Num_Length];
  99.     *R_Search_PhNum = NULL;
  100.     printf("Name:"); scanf("%s", R_Search_Name);
  101.    
  102.     StartCounter();
  103.     BiT_Node *R_SearchData = NULL;
  104.     R_SearchData = Make_Tree(R_Search_Name, R_Search_PhNum);
  105.     BiT_Node * Result = Search_No_Recursion(Expo, R_SearchData);
  106.    
  107.     printf("Running time is: %lfms\n", GetCounter()*1000);
  108.     if (Result != NULL)
  109.         printf("Data Found\n");
  110.     return 0;
  111. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top