Advertisement
Frinom

lab10/deleting

Nov 11th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include "stdafx.h"
  2. using namespace std;
  3. Dictionary* deletingWords(Dictionary *dict, int &emptyArr)
  4. {
  5.     system("cls");
  6.     print(dict, emptyArr,0);
  7.     if (emptyArr > 0)
  8.     {
  9.         char word[31];
  10.         cout << "Введите слово, которое хотите удалить: ";
  11.         cin >> word;
  12.         bool flag = false;
  13.         for (int i = 0; i < emptyArr; i++)
  14.         {
  15.             if (simular(dict[i].engl, word))
  16.             {
  17.                 flag = true;
  18.                 for (int j = 0; j < length(dict[i].engl); j++)
  19.                     dict[i].engl[j] = 'z';
  20.                 break;
  21.             }
  22.         }
  23.  
  24.         if (flag)
  25.         {
  26.             sort(dict, emptyArr);
  27.  
  28.             Dictionary *temp;
  29.  
  30.             if (emptyArr == 1)
  31.             {
  32.                 temp = new Dictionary[1];
  33.                 temp[0].engl = new char[2];
  34.                 temp[0].engl[0] = ' ';
  35.                 temp[0].engl[1] = '\0';
  36.  
  37.                 temp[0].rus = new char[2];
  38.                 temp[0].rus[0] = ' ';
  39.                 temp[0].rus[1] = '\0';
  40.  
  41.                 delete[] dict;
  42.  
  43.                 dict = temp;
  44.                 emptyArr--;
  45.                 temp = nullptr;
  46.             }
  47.             else
  48.             {
  49.                 temp = new Dictionary[emptyArr - 1];
  50.  
  51.                 for (int i = 0; i < emptyArr - 1; i++)
  52.                 {
  53.                     temp[i].engl = new char[length(dict[i].engl) + 1];
  54.                     for (int j = 0; j < length(dict[i].engl); j++)
  55.                     {
  56.                         temp[i].engl[j] = dict[i].engl[j];
  57.                     }
  58.                     temp[i].engl[length(dict[i].engl)] = '\0';
  59.  
  60.                     temp[i].rus = new char[length(dict[i].rus) + 1];
  61.                     for (int j = 0; j < length(dict[i].rus); j++)
  62.                     {
  63.                         temp[i].rus[j] = dict[i].rus[j];
  64.                     }
  65.                     temp[i].rus[length(dict[i].rus)] = '\0';
  66.  
  67.                 }
  68.                 delete[] dict;
  69.  
  70.                 emptyArr--;
  71.  
  72.                 dict = temp;
  73.  
  74.                 temp = nullptr;
  75.             }
  76.         }
  77.         else cout << "Слово для удаления не было найдено!" << endl;
  78.     }
  79.     else cout << "Словарь пуст" << endl;
  80.     return dict;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement