Advertisement
Savelyev_Vyacheslav

Examen C++

Jan 15th, 2021 (edited)
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.19 KB | None | 0 0
  1. ////////////////
  2. Delete_end()
  3. {
  4.     Node *temp = NULL;
  5.     Node *head2 = head;
  6.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  7.     while (head2->ptr != NULL) {  // перемотка на последние указатели
  8.         temp = head2;
  9.         head2 = head2->ptr;
  10.     }
  11.     if (temp) {
  12.         //<udalenie poslednego>
  13.         temp->ptr = NULL;
  14.         delete head2;
  15.         //< /udalenie poslednego>
  16.     }
  17. }
  18. ////////////////
  19. Delete_prev_end()
  20. {
  21.     Node *temp = NULL;
  22.     Node *head2 = head;
  23.     Node *t = head;
  24.     Node *t2 = head;
  25.     Node *t3 = head;
  26.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  27.     if (head2->ptr == NULL) { return NULL; } // В списке нет узлов по условию
  28.     if (head2->ptr->ptr == NULL) { return NULL; } // В списке нет узлов
  29.     int j = 0;
  30.     cout << head2->FirstName << " - " << head2 << " - " << endl;
  31.     while (head2->ptr != NULL) {j++;
  32.                 head2 = head2->ptr;
  33.                 temp = head2;
  34.                 t = temp->ptr;
  35.                 t3 = t->ptr;
  36.         if (head2->ptr->ptr->ptr == NULL) {
  37.             //// <operation>
  38.             temp->ptr = t3; delete t;
  39.             //// </operation>
  40.             return NULL;
  41.         }
  42.     }
  43. }
  44. ///////////////////
  45. ////////////////
  46. head_del()
  47. {
  48.     Node *temp = NULL;
  49.     Node *head2 = head;
  50.     Node *t = head;
  51.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  52.     //<operation>
  53.     head = head2->ptr;
  54.     t = NULL;
  55.     delete t;
  56.     //</operation>
  57. }
  58. ////////////////
  59. ////////////////
  60. head_next_del()
  61. {
  62.     Node *t1 = NULL;
  63.     Node *head2 = head;
  64.     Node *t2 = head;
  65.     Node *t3 = head;
  66.     t1 = head;
  67.     t2 = t1->ptr;
  68.     t3 = t2->ptr;
  69.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  70.     // <operation>
  71.     t1->ptr = t3;
  72.     t2->ptr = NULL;
  73.     delete t2;
  74.     // </operation>
  75. }
  76. ////////////////
  77. ////////////////
  78. Dobav_head()
  79. {
  80.     string value;
  81.     Node *temp = NULL;
  82.     Node *head2 = head;
  83.     cin >> value;
  84.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  85.     //<opation>
  86.     Node *elem2 = new Node();
  87.     elem2->FirstName = value;
  88.     elem2->ptr = head2;
  89.     head = elem2;
  90.     //</opation>
  91.    
  92. }
  93. ////////////////
  94. Dobav_head_next()
  95. {
  96.     Node *t1 = NULL;
  97.     Node *t2 = head;
  98.     t1 = head;
  99.     t2 = t2->ptr;
  100.     if (t2 == NULL) { return NULL; } // В списке нет узлов
  101.     //<operation>
  102.     Node *elem2 = new Node();
  103.     elem2->FirstName = "88";
  104.     t1->ptr = elem2;
  105.     elem2->ptr = t2;
  106.     //<operation>
  107. }
  108. ////////////////
  109. ////////////////
  110. Dobav_n_last()
  111. {  
  112.     string value = "88"
  113.     Node *temp = NULL;
  114.     Node *head2 = head;
  115.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  116.     while (head2->ptr != NULL) {
  117.         temp = head2;
  118.         head2 = head2->ptr;
  119.     }
  120.     // <operation>
  121.     Node *elem2 = new Node();
  122.     elem2->FirstName = value;
  123.     elem2->ptr = NULL;
  124.     head2->ptr = elem2;
  125.     // </operation>
  126. }
  127. ////////////////
  128.  
  129. /////////////////
  130. Dobav_pre_last()
  131. {  
  132.     Node *temp = NULL;
  133.     Node *t = head;
  134.     Node *head2 = head;
  135.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  136.     while (head2->ptr != NULL) {
  137.     head2 = head2->ptr;
  138.     t = t->ptr;
  139.         if (t->ptr->ptr == NULL) {
  140.         temp = t->ptr;
  141.         //<operation>
  142.         Node *elem2 = new Node();
  143.         elem2->FirstName = "88";
  144.         t->ptr = elem2;
  145.         elem2->ptr = temp;
  146.         //</operation>
  147.         return NULL;
  148.         }
  149.     }
  150. }
  151. ////////////////
  152. //chtenie
  153. reedOfFile(string nameFile)
  154. {
  155.     ifstream inf(nameFile);
  156.     // Если мы не можем открыть файл для чтения его содержимого,
  157.     if (!inf)
  158.     {
  159.         // то выводим следующее сообщение об ошибке и выполняем функцию exit()
  160.         cerr << "SetText.txt could not be opened for reading!" << endl;
  161.         exit(1);
  162.     }
  163.     string strInput2;
  164.     // Пока есть, что читать,
  165.     while (inf)
  166.     {
  167.         // то перемещаем то, что можем прочитать, в строку, а затем выводим эту строку на экран
  168.         string strInput;
  169.         getline(inf, strInput);
  170.         strInput2 = strInput2 + strInput;
  171.     }
  172.     return strInput2;
  173.     //cout << strInput2 << endl;
  174. }
  175. ///////////////////
  176. // Zapis
  177.  {
  178.         using namespace std;
  179.         ofstream outf("SetText.txt");
  180.         if (!outf)
  181.         {
  182.  
  183.             cerr << "SetText.txt could not be opened for writing!" << endl;
  184.             exit(1);
  185.         }
  186.         for (i = 0; i < N; i++) {
  187.             outf << fly[i].punkt << "    " << fly[i].numb << "    " << fly[i].type << endl;
  188.         }
  189.     }
  190. ////////////////
  191. Node* List::By_value_del()
  192. {
  193.     Node *temp = NULL;
  194.     Node *head2 = head;
  195.     Node *t = head;
  196.     Node *t2 = head;
  197.     Node *t3 = head;
  198.     Node *t4 = head;
  199.     Node *tail = head;
  200.  
  201.     string value_del = "31";
  202.     cin >> value_del;
  203.    
  204.     while (tail->ptr != NULL) {
  205.         tail = tail->ptr;
  206.     }
  207.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  208.     else if (head2->FirstName == value_del) {  // kluch v golove
  209.         head_del();
  210.     }
  211.     else if (tail->FirstName == value_del) { // kluch v hvoste
  212.         Delete_end();
  213.     }
  214.     else {
  215.     int j = 0;
  216.     while (head2 != NULL) {
  217.         temp = head2;
  218.         t = temp->ptr;
  219.         if (t->FirstName == value_del) {
  220.             t3 = t->ptr;
  221.             //// <operation>
  222.             temp->ptr = t3; delete t;
  223.             //// </operation>
  224.             break;
  225.         }
  226.         head2 = head2->ptr;
  227.         j++;
  228.     }
  229.   }
  230. }
  231. ///////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement