SHARE
TWEET

Untitled

daniil_mironoff Nov 19th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const unsigned int MAXSIZE = 32;
  6.  
  7. struct item {
  8.     char name[32];
  9.     char number[32];
  10.  
  11.     item* next = NULL;
  12. };
  13.  
  14. struct list {
  15.     item* first = NULL;
  16. };
  17.  
  18.  
  19.  
  20. void list_push_back(list& data, item* obj) {
  21.     obj -> next = data.first;
  22.     data.first  = obj;
  23. }
  24.  
  25. void list_display(list& data) {
  26.     item* temp = data.first;
  27.    
  28.     while(temp) {
  29.         cout << temp -> name << ' ' << temp -> number << endl;
  30.         temp = temp -> next;
  31.     }
  32. }
  33.  
  34. item* create_human(char* argName, char* argNumber) {
  35.     item* newHuman = new item;
  36.    
  37.     // Проверка на длину имени
  38.     for (int i = 0; true; i++) {
  39.         newHuman -> name[i] = argName[i];
  40.  
  41.         if (argName[i] == 0) {
  42.             break;
  43.         }
  44.  
  45.         if (i == MAXSIZE) {
  46.             exit(1);
  47.         }
  48.     }
  49.    
  50.     // Проверка на длину номера
  51.     for (int i = 0; true; i++) {
  52.         newHuman -> number[i] = argNumber[i];
  53.  
  54.         if (argNumber[i] == 0) {
  55.             break;
  56.         }
  57.  
  58.         if (i == MAXSIZE) {
  59.             exit(1);
  60.         }
  61.     }
  62.  
  63.     return newHuman;
  64. }
  65.  
  66.  
  67.  
  68. void find_item_number(list& data, char* number) {
  69.     item* temp = data.first;
  70.    
  71.     while(temp) {
  72.         bool find = true;
  73.  
  74.         for (int i = 0; (temp -> number[i]) != 0; i++) {
  75.             if (temp -> number[i] != number[i]) {
  76.                 find = false;
  77.                 break;
  78.             }
  79.         }
  80.  
  81.         if (find) {
  82.             cout << "Find number " << number << ": " << temp -> name << endl;
  83.         }
  84.  
  85.         temp = temp -> next;
  86.     }
  87. }
  88.  
  89. void find_item_name(list& data, char* name) {
  90.     item* temp = data.first;
  91.    
  92.     while(temp) {
  93.         bool find = true;
  94.  
  95.         for (int i = 0; (temp -> name[i]) != 0; i++) {
  96.             if (temp -> name[i] != name[i]) {
  97.                 find = false;
  98.                 break;
  99.             }
  100.         }
  101.  
  102.         if (find) {
  103.             cout << "Find name " << name << ": " << temp -> number << endl;
  104.         }
  105.  
  106.         temp = temp -> next;
  107.     }
  108. }
  109.  
  110. int main() {
  111.     list numbersBook;
  112.     list_push_back(numbersBook, create_human("Daniil", "89829758597"));
  113.     list_push_back(numbersBook, create_human("Maxim", "89222550206"));
  114.     list_push_back(numbersBook, create_human("Daniil", "89723948206"));
  115.     list_push_back(numbersBook, create_human("Leha", "89222550206"));
  116.    
  117.     list_display(numbersBook);
  118.  
  119.     cout << endl;
  120.  
  121.     find_item_name(numbersBook, "Daniil");
  122.     find_item_number(numbersBook, "89222550206");
  123.  
  124.    
  125.     return 0;
  126. }
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