Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream> // chtenie faila
- #include <stdlib.h> //for using the function sleep
- #include <windows.h> // для Win32 систем
- #include <clocale>
- using namespace std;
- class Otsenki {
- string fizika;
- string istoriya;
- string informatika;
- friend class List;
- friend class Node;
- };
- class Node
- {
- string FirstName;
- string LastName;
- string N_student;
- Otsenki *OtsenkiPtr = new Otsenki();
- class Node *ptr;
- friend class List;
- };
- class List
- {
- Node *head;
- int count = 0;
- Node* Prev(Node *); // Переход к предыдущему узлу (не интерфейсный метод)
- public:
- List() { head = NULL; } // Инициализация списка
- int getCount() { return count; } // Получение количества узлов списка
- bool isEmpty() { return head == NULL; } // Проверка, пуст ли список
- string getValue(Node* p) { return p->N_student; } // Получение значения узла списка
- string getValue2(Node* p) { return p->FirstName; } // Получение значения узла списка
- string getValue3(Node* p) { return p->LastName; } // Получение значения 2го узла списка
- string getValue4(Node* p) { return p->OtsenkiPtr->fizika; }
- string getValue5(Node* p) { return p->OtsenkiPtr->istoriya; }
- string getValue6(Node* p) { return p->OtsenkiPtr->informatika; }
- Node* Add(string, string, string, string, string, string, Node*); // Добавление узла списка
- Node* ChekValidALL(string, string, string, string, string, string); // Добавление узла списка
- void setValue(Node *p, int val) { p->FirstName = val; } // Установка значения узла списка
- Node* getFirst() { return head; } // Получение корневого узла списка
- Node* getLast(); // Получение последнего узла списка
- void Clear(); // Очистка списка
- Node* Next(Node *); // Переход к следующему узлу
- Node* Delete(Node*); // Удаление узла списка
- void Print(); // Вывод значений узлов списка
- void Swap(Node*, Node*); // Взаимообмен двух узлов
- void String_total_X(); // поиск X
- int ValidText(string);
- int ValidChislo(string);
- string reedOfFile(string);
- void Delete_ALL();
- Node* Print_By_value();
- int CountElement();
- Node* Nomer_s_kontsa_del(); // удален середина по номеру
- Node* Zamena(); // замена
- Node* Zamena_ptr(); // замена по указателю
- Node* HeadToEnd(); // замена местами по указателю первый назад последний вперед
- Node* FILO(); // первый назад
- Node* LIFO(); // последний вперед
- void StekOperation(); // DZ po AIP
- Node* Dobav_n_last(string); // добавить в конец
- Node* Dobav_pre_last(); // добавить перед конец
- Node* Dobav_head(); // добавить перед конец
- Node* Dobav_head_next(); // добавить перед конец
- Node* head_del(); // udalit golovu
- Node* head_next_del(); // udalit 2 s golovu
- Node* Delete_end(); // удаляет конец
- Node* Delete_prev_end(); // удален предпоследний
- Node* Del_By_value(); // udalit po znacheniu
- void WriteFromProgToTxt(string);
- void ReedOfTxtToProg(string);
- };
- Node* List::ChekValidALL(string num1, string num2, string num3, string num4, string num5, string num6)
- {
- if (!ValidChislo(num1)) { cout << " 1-N_student "; return NULL; }
- if (!ValidText(num2)){ cout << " 2-FirstName "; return NULL; }
- if (!ValidText(num3)) { cout << " 3-LastName "; return NULL; }
- if (!ValidChislo(num4)) { cout << " 4-fizika "; return NULL; }
- if (!ValidChislo(num5)) { cout << " 5-istoriya "; return NULL; }
- if (!ValidChislo(num6)) { cout << " 6-informatika "; return NULL; }
- }
- Node* List::Add( string num1, string num2, string num3, string num4, string num5, string num6, Node* node = NULL)
- {
- ChekValidALL(num1,num2, num3, num4, num5, num6);
- Node *elem = new Node();
- elem->N_student = num1;
- elem->FirstName = num2;
- elem->LastName = num3;
- elem->OtsenkiPtr->fizika = num4;
- elem->OtsenkiPtr->istoriya = num5;
- elem->OtsenkiPtr->informatika = num6;
- count++;
- if (node == NULL) // Добавление нового корня
- {
- if (head == NULL) {
- elem->ptr = NULL;
- head = elem;
- }
- else {
- elem->ptr = head;
- head = elem;
- }
- return elem;
- }
- elem->ptr = node->ptr; // Добавление узла после текущего
- node->ptr = elem;
- return elem;
- }
- Node* List::Delete(Node* node)
- {
- if (node == NULL) { return NULL; } // В списке нет узлов
- count--;
- if (node == head) // Удаление корневого узла
- {
- head = node->ptr;
- delete node;
- return head;
- }
- Node* prev = Prev(node); // Удаление промежуточного узла
- prev->ptr = node->ptr;
- delete node;
- return prev;
- }
- ////////////////
- Node* List::Delete_end()
- {
- Node *temp = NULL;
- Node *head2 = head;
- if (head2 == NULL) { return NULL; } // В списке нет узлов
- count--;
- while (head2->ptr != NULL) { // перемотка на последние указатели
- temp = head2;
- head2 = head2->ptr;
- }
- if (temp) {
- //<udalenie poslednego>
- temp->ptr = NULL;
- delete head2;
- //< /udalenie poslednego>
- }
- cout << temp->FirstName << " - " << temp << " - " << temp->ptr << endl;
- }
- ////////////////
- ////////////////
- Node* List::Dobav_head()
- {
- Node *temp = NULL;
- Node *head2 = head;
- //Node *uzel = head;
- //cout << "add to head: ";
- string z1, z2, z3, z4, z5, z6;
- cin >> z1 >> z2 >> z3 >> z4 >> z5 >> z6;
- ChekValidALL(z1, z2, z3, z4, z5, z6);
- //<opation>
- Node *elem = new Node();
- elem->N_student = z1;
- elem->FirstName = z2;
- elem->LastName = z3;
- elem->OtsenkiPtr->fizika = z4;
- elem->OtsenkiPtr->istoriya = z5;
- elem->OtsenkiPtr->informatika = z6;
- elem->ptr = head2;
- head = elem;
- //</opation>
- if (head2 == NULL) { return NULL; } // В списке нет узлов
- count++;
- }
- ////////////////
- ////////////////
- Node* List::Dobav_head_next()
- {
- Node *t1 = NULL;
- Node *t2 = head;
- t1 = head;
- t2 = t2->ptr;
- //<operation>
- Node *elem2 = new Node();
- elem2->FirstName = "88";
- t1->ptr = elem2;
- elem2->ptr = t2;
- //<operation>
- if (t2 == NULL) { return NULL; } // В списке нет узлов
- count++;
- }
- ////////////////
- ////////////////
- Node* List::Dobav_n_last(string value = "88")
- {
- Node *temp = NULL;
- Node *head2 = head;
- if (head2 == NULL) { return NULL; } // В списке нет узлов
- count++;
- while (head2->ptr != NULL) {
- temp = head2;
- head2 = head2->ptr;
- }
- // <operation>
- Node *elem2 = new Node();
- elem2->FirstName = value;
- elem2->ptr = NULL;
- head2->ptr = elem2;
- // </operation>
- cout << head2->FirstName << " test " << head2 << " test " << endl;
- cout << head2->ptr->FirstName << " test " << head2->ptr << " test " << endl;
- }
- ////////////////
- /////////////////
- Node* List::Dobav_pre_last()
- {
- Node *temp = NULL;
- Node *t = head;
- Node *head2 = head;
- if (head2 == NULL) { return NULL; } // В списке нет узлов
- count--;
- while (head2->ptr != NULL) {
- head2 = head2->ptr;
- t = t->ptr;
- if (t->ptr->ptr == NULL) {
- temp = t->ptr;
- cout << t->FirstName << " test2 " << t << " test2 " << endl;
- cout << temp->FirstName << " test2 " << temp->ptr << " test2 " << endl;
- //<operation>
- Node *elem2 = new Node();
- elem2->FirstName = "88";
- t->ptr = elem2;
- elem2->ptr = temp;
- //</operation>
- return NULL;
- }
- }
- }
- ////////////////
- ////////////////
- Node* List::Delete_prev_end()
- {
- count++;
- Node *temp = NULL;
- Node *head2 = head;
- Node *t = head;
- Node *t2 = head;
- Node *t3 = head;
- if (head2 == NULL) { return NULL; } // В списке нет узлов
- if (head2->ptr == NULL) { return NULL; } // В списке нет узлов по условию
- if (head2->ptr->ptr == NULL) { return NULL; } // В списке нет узлов
- count--;
- int j = 0;
- cout << head2->FirstName << " - " << head2 << " - " << endl;
- while (head2->ptr != NULL) {
- j++;
- head2 = head2->ptr;
- temp = head2;
- t = temp->ptr;
- t3 = t->ptr;
- cout << temp->FirstName << " - " << temp << " - " << endl;
- cout << t->FirstName << " - " << t << " - " << endl;
- cout << t3->FirstName << " - " << t3 << " - " << endl;
- if (head2->ptr->ptr->ptr == NULL) {
- //// <operation>
- temp->ptr = t3; delete t;
- //// </operation>
- cout << temp->FirstName << " Проверка " << temp << " - " << endl;
- cout << temp->ptr->FirstName << " Проверка " << temp->ptr << " - " << endl;
- cout << "temp->ptr->ptr->FirstName" << " Проверка " << temp->ptr->ptr << " - " << endl;
- cout << "t3->ptr->FirstName" << " - " << t3->ptr << " - " << endl;
- return NULL;
- }
- }
- }
- ///////////////////
- ////////////////
- Node* List::Nomer_s_kontsa_del()
- {
- count++;
- Node *temp = NULL;
- Node *head2 = head;
- Node *t = head;
- Node *t2 = head;
- Node *t3 = head;
- Node *t4 = head;
- int nomer_s_kontsa = 4;
- if (head2 == NULL) { return NULL; } // В списке нет узлов
- count--;
- int i = 0;
- int vsego;
- while (t2->ptr != NULL) {
- t2 = t2->ptr;
- i++;
- vsego = i;
- }
- // proverka na sootvetstvie spisku
- if ((vsego + 1) <= nomer_s_kontsa) { cout << " Nomer ne sootvetstvuet spisku|" << nomer_s_kontsa << "- этого номера нет " << endl; return NULL; }
- cout << " vsego " << (vsego + 1) << " - " << endl;
- int j = 0;
- while (head2->ptr != NULL) {
- if (j == (vsego - nomer_s_kontsa)) {
- temp = head2;
- t = temp->ptr;
- t3 = t->ptr;
- //// <perenos ukazatelya udalenie>
- temp->ptr = t3; delete t;
- //// </ perenos ukazatelya udalenie>
- cout << j << " Проверка " << temp << " - " << endl;
- head2 = head2->ptr;
- }
- else {
- head2 = head2->ptr;
- }
- j++;
- }
- }
- ///////////////////
- int List::CountElement()
- {
- Node *t = head;
- int i = 0;
- int vsego;
- while (t->ptr != NULL) {
- t = t->ptr;
- i++;
- vsego = i;
- }
- return vsego;
- }
- ////////////////
- Node* List::Del_By_value()
- {
- Node *temp = NULL;
- Node *head2 = head;
- Node *t = head;
- Node *t2 = head;
- Node *t3 = head;
- Node *t4 = head;
- Node *tail = head;
- string value_del;
- cin >> value_del;
- if (head2 == NULL) { cout << "pusto "; return NULL; } // В списке нет узлов
- if (head2->ptr == NULL) { cout << "udali vse "; return NULL; } // В списке 1 узел
- while (tail->ptr != NULL) {
- tail = tail->ptr;
- //cout << " Проверка222 " << tail->FirstName << " - " << endl;
- }
- if (head2->ptr->ptr == NULL) {
- if (head2->LastName == value_del) { // kluch v golove
- head_del(); //cout << "test ";
- }
- if (tail->LastName == value_del) { // kluch v hvoste
- Delete_end();
- }
- return NULL; } // В списке 2 узла
- else {
- int j = 0;
- while (head2 != NULL) {
- temp = head2;
- t = temp->ptr;
- if (t->LastName == value_del) {
- t3 = t->ptr;
- //// <operation>
- temp->ptr = t3; delete t;
- //// </operation>
- //cout << j << " Проверка " << temp->FirstName << " - " << endl;
- //cout << j << " Проверка " << t->FirstName << " - " << endl;
- //cout << j << " Проверка " << t3->FirstName << " - " << endl;
- break;
- }
- head2 = head2->ptr;
- j++;
- }
- }
- }
- ///////////////////
- ////////////////
- Node* List::Print_By_value()
- {
- Node *head2 = head;
- string value_del;
- cout << " Vvedite FAMELIU dlya poiska > ";
- cin >> value_del;
- if (head2 == NULL) { return NULL; } // В списке нет узлов
- while (head2 != NULL) {
- if (head2->LastName == value_del) {
- //typ[0];
- cout << " Nomer > " << head2->N_student << " < " << head2->FirstName+' '<< head2->LastName + ' ' << head2->OtsenkiPtr->fizika + ' ' << head2->OtsenkiPtr->istoriya + ' ' << head2->OtsenkiPtr->informatika + ' ' << endl;
- }
- head2 = head2->ptr;
- }
- }
- ///////////////////
- ////////////////
- Node* List::head_next_del()
- {
- Node *t1 = NULL;
- Node *head2 = head;
- Node *t2 = head;
- Node *t3 = head;
- t1 = head;
- t2 = t1->ptr;
- t3 = t2->ptr;
- if (head2 == NULL) { return NULL; } // В списке нет узлов
- // <ukazateli dlya operatsii>
- cout << t1->FirstName << " - " << t1 << " - " << endl;
- cout << t2->FirstName << " - " << t2 << " - " << endl;
- cout << t3->FirstName << " - " << t3 << " - " << endl;
- // </ukazateli dlya operatsii>
- // <operation>
- t1->ptr = t3;
- t2->ptr = NULL;
- delete t2;
- // </operation>
- // <proverka>
- cout << head2->FirstName << " - " << head2 << " - " << endl;
- cout << head2->ptr->FirstName << " - " << head2->ptr << " - " << endl;
- cout << head2->ptr->ptr->FirstName << " - " << head2->ptr->ptr << " - " << endl;
- // </proverka>
- }
- ////////////////
- ////////////////
- Node* List::head_del()
- {
- Node *h = head;
- Node *t = head;
- if (h == NULL) { return NULL; } // В списке нет узлов
- //<operation>
- head = h->ptr;
- t = NULL;
- delete t;
- //</operation>
- }
- ////////////////
- ////////////////
- Node* List::Zamena_ptr()
- {
- Node *temp = NULL;
- Node *head2 = head;
- Node *t = head;
- Node *t2 = head;
- Node *t3 = head;
- Node *t4 = head;
- if (head2 == NULL) { return NULL; } // В списке нет узлов
- int i = 0;
- int n_zameny = 3;
- while (head2->ptr != NULL) {
- t2 = head2;
- head2 = head2->ptr;
- if (i == (n_zameny - 2)) {
- temp = head2;
- cout << " Замена " << n_zameny << endl;
- head2 = head2->ptr;
- t3 = temp->ptr;
- // <vivod nuzhnih peremennih>
- cout << t->FirstName << " - " << t << " - " << endl;
- cout << t2->FirstName << " - " << t2 << " - " << endl;
- cout << temp->FirstName << " - " << temp << " - " << endl;
- cout << t3->FirstName << " - " << t3 << " - " << endl;
- // </vivod nuzhnih peremennih>
- // </ operation>
- t4 = t4->ptr; // второй
- t2->ptr = t; // связь перед t. t был первым
- t->ptr = t3; // связь после t. t был первым
- head = temp; // новый хэд темп выбран по номеру n_zameny
- temp->ptr = t4; // указатель на второй
- // < operation>
- // < proverka>
- cout << head->FirstName << " 1 " << head << " - " << endl;
- cout << t2->FirstName << " n " << t2 << " - " << endl;
- cout << t2->ptr->FirstName << " n+1 " << t2->ptr << " - " << endl;
- cout << t3->FirstName << " n+2 " << t3 << " - " << endl;
- // < proverka>
- }
- i++;
- }
- }
- ///////////////////
- ////////////////
- Node* List::HeadToEnd()
- {
- Node *temp = NULL;
- Node *head2 = head;
- Node *t = head;
- Node *t2 = head;
- Node *t3 = head;
- Node *t4 = head;
- if (head2 == NULL) { return NULL; } // В списке нет узлов
- int i = 0;
- int n_zameny = 10;
- while (head2->ptr != NULL) {
- head2 = head2->ptr;
- t2 = head2;
- if (t2->ptr->ptr->ptr == NULL) {
- t2 = head2;
- temp = t2->ptr;
- cout << " Замена " << n_zameny << endl;
- //head2 = head2->ptr;
- t3 = temp->ptr;
- // <vivod nuzhnih peremennih>
- cout << t->FirstName << " - " << t << " - " << endl;
- cout << t2->FirstName << " - " << t2 << " - " << endl;
- cout << temp->FirstName << " - " << temp << " - " << endl;
- cout << t3->FirstName << " - " << t3 << " - " << endl;
- // </vivod nuzhnih peremennih>
- // </ podstanovka>
- t4 = t4->ptr;
- head = t3;
- t3->ptr = t4;
- temp->ptr = t; t->ptr = NULL;
- // < podstanovka>
- return NULL;
- }
- i++;
- }
- }
- ///////////////////
- ////////////////
- Node* List::LIFO()
- {
- Node *temp = NULL;
- Node *head2 = head;
- Node *t = head;
- Node *tt = head;
- Node *t2 = head;
- Node *t3 = head;
- Node *t4 = head;
- if (head2 == NULL) { return NULL; } // В списке нет узлов
- int i = 0;
- int n_zameny = 10;
- while (head2->ptr != NULL) {
- t2 = head2;
- t4 = t2->ptr;
- if (t2->ptr->ptr == NULL) {
- // <vivod nuzhnih peremennih>
- cout << t2->FirstName << " -- " << t2 << " - " << endl;
- cout << t4->FirstName << " -- " << t4 << " - " << endl;
- // </vivod nuzhnih peremennih>
- // </ podstanovka>
- head = t4;
- t4->ptr = t3;
- t2->ptr = NULL;
- // < podstanovka>
- return NULL;
- }
- head2 = head2->ptr; t2 = t2->ptr;
- i++;
- }
- }
- ///////////////////
- ////////////////
- Node* List::FILO()
- {
- Node *temp = NULL;
- Node *head2 = head;
- Node *t = head;
- Node *tt = head;
- Node *t2 = head;
- Node *t3 = head;
- Node *t4 = head;
- if (head2 == NULL) { return NULL; } // В списке нет узлов
- int i = 0;
- while (head2->ptr != NULL) {
- head2 = head2->ptr;
- t2 = head2;
- if (t2->ptr == NULL) {
- t2 = head2;
- temp = t2->ptr;
- // <vivod nuzhnih peremennih>
- //cout << t->FirstName << " -- " << t << " - " << endl;
- //cout << t2->FirstName << " -- " << t2 << " - " << endl;
- // </vivod nuzhnih peremennih>
- // </ podstanovka>
- t4 = t4->ptr;
- head = t4;
- t2->ptr = t;
- t->ptr = NULL;
- // < podstanovka>
- return NULL;
- }
- i++;
- }
- }
- ///////////////////
- ////////////////
- Node* List::Zamena()
- {
- Node *temp = NULL;
- Node *head2 = head;
- Node *t = head;
- if (head2 == NULL) { return NULL; } // В списке нет узлов
- int i = 0;
- int n_zameny;
- cout << " Введи номер замены " << endl;
- cin >> n_zameny;
- while (head2->ptr != NULL) {
- if (i == (n_zameny - 1)) {
- temp = head2;
- cout << " Замена " << n_zameny << endl;
- }
- head2 = head2->ptr;
- cout << i << " - " << t << " - " << endl;
- cout << i << " - " << temp << " - " << endl;
- cout << i << " - " << head2->ptr << " - " << endl;
- i++;
- }
- if (temp) {
- string zamen1;
- zamen1 = temp->FirstName;
- temp->FirstName = t->FirstName; // вставляем значение первого в выбранный
- t->FirstName = zamen1; // вставляем в первый значение выбранного
- }
- }
- ///////////////////
- ////////////////
- void List::StekOperation()
- {
- while (true)
- {
- int opN;
- cout << "Operation Dobav_head-1 head_del-2 AddTail-3 DelTail-4 Print-5 Delet_ALL-6 ReedOf.Txt-7 \n";
- cout << " WriteFromProgToTxt-8 Print_By_value-9 Del_By_value-10 Exit-anyButton \n" ;
- cin >> opN;
- switch (opN) {
- case 1:
- cout << "Dobav_head\n"; Dobav_head();
- break;
- case 2:
- cout << "head_del\n"; head_del();
- break;
- case 3:
- cout << "AddTail\n"; Dobav_head(); FILO();
- break;
- case 4:
- cout << "DelTail\n"; LIFO(); head_del();
- break;
- case 5:
- cout << "Print\n"; Print();
- break;
- case 6:
- cout << "Delete_ALL\n"; Delete_ALL();
- break;
- case 7:
- cout << "ReedOfTxtToProg\n"; ReedOfTxtToProg("write.txt");
- break;
- case 8:
- cout << "WriteFromProgToTxt\n"; WriteFromProgToTxt("write.txt");
- break;
- case 9:
- cout << "Print_By_value\n"; Print_By_value();
- break;
- case 10:
- cout << "Del_By_value\n"; Del_By_value();
- break;
- default:
- cout << "Exit\n"; goto tryAgain;
- }
- }
- tryAgain: // это лейбл
- exit;
- }
- ///////////////////
- void List::Print()
- {
- if (isEmpty()) { cout << "Список пуст" << endl; return; }
- Node *p = head;
- do {
- cout << getValue(p)
- << " " << getValue2(p)
- << " " << getValue3(p)
- << " " << getValue4(p)
- << " " << getValue5(p)
- << " " << getValue6(p)
- << "\n";
- p = Next(p);
- } while (p != NULL);
- cout << endl;
- }
- void List::Clear()
- {
- class Node *p = head;
- if (p == NULL) return;
- do {
- Node *d = p;
- p = Next(p);
- delete d;
- } while (p != NULL);
- count = 0;
- head = NULL;
- }
- void List::Delete_ALL()
- {
- class Node *p = head;
- if (p == NULL) return;
- do {
- Node *d = p;
- p = p->ptr;
- delete d;
- } while (p != NULL);
- count = 0;
- head = NULL;
- }
- Node* List::getLast()
- {
- Node* p = head;
- while (Next(p) != NULL)
- p = Next(p);
- return p;
- }
- Node* List::Next(Node* node)
- {
- if (isEmpty()) return NULL;
- return node->ptr;
- }
- Node* List::Prev(Node* node)
- {
- if (isEmpty()) return NULL;
- if (node == head) return NULL;
- Node *p = head;
- while (p->ptr != node)
- p = p->ptr;
- return p;
- }
- void List::String_total_X() {
- string nameFile="students.txt";
- string s = reedOfFile(nameFile);
- //<podschet vseh simvolov v tekste>
- ifstream inf(nameFile);
- //cout << "start str";
- int p = 0;
- int i = 0;
- while (inf)
- { i++;
- cout << "\n<-----str#"<< i << "/---->" <<endl;
- // то перемещаем то, что можем прочитать, в строку, а затем выводим эту строку на экран
- string str;
- getline(inf, str);
- cout << str;
- p = 0;
- if (str.find('X') != -1) {
- //ValidText(s);
- cout << "\n<----/str#" << i << "----->";
- cout << " Elementov v stroke - ";
- for (auto c : str)
- if (c == 'X') {
- p++;
- }
- cout << p << "\n";
- }
- }
- p = 0;
- if (s.find('X') != -1) {
- cout << "\n" << "\nVsego elementov v spiske ";
- for (auto c : s)
- if (c == 'X') {
- p++;
- }
- cout << p << "\n\n";
- }
- std::system("pause");
- //</podschet vseh simvolov v tekste>
- }
- ////////////////
- int List::ValidText(string s) {
- for (auto c : s)
- if ((c <= '9')&&(c >= '0')) {
- cout << "Vi vveli cislo ne tuda";
- return 0;
- }
- return 1;
- }
- ////////////////
- ////////////////
- int List::ValidChislo(string s) {
- for (auto c : s) {
- if ((c <= 'z') && (c >= 'a')) {
- cout << "Vi vveli text ne tuda"; return 0;
- }
- else if ((c <= 'Z') && (c >= 'A')) {
- cout << "Vi vveli text ne tuda"; return 0;
- }
- else if ((c <= 'Я') && (c >= 'А')) {
- cout << "Vi vveli text ne tuda"; return 0;
- }
- else if ((c <= 'я') && (c >= 'а')) {
- cout << "Vi vveli text ne tuda"; return 0;
- }
- }
- return 1;
- }
- ////////////////
- void List::WriteFromProgToTxt(string path = "write.txt")
- {
- //string path = "write.txt";
- ofstream fout;
- fout.open(path, ofstream::app);
- if (!fout.is_open()) {
- cout << "Ошибка открытия фаила"<< endl;
- Sleep(5000);
- }
- else {
- if (isEmpty()) { cout << "Список пуст" << endl; return; }
- Node *p = head;
- do {
- fout << getValue(p)
- << " " << getValue2(p)
- << " " << getValue3(p)
- << " " << getValue4(p)
- << " " << getValue5(p)
- << " " << getValue6(p)
- << "\n";
- p = Next(p);
- } while (p != NULL);
- }
- fout.close();
- }
- ///////////////////
- ////////////////
- void List::ReedOfTxtToProg(string nameFile="write.txt")
- {
- ifstream inf(nameFile);
- // Если мы не можем открыть файл для чтения его содержимого,
- if (!inf)
- {
- // то выводим следующее сообщение об ошибке и выполняем функцию exit()
- cerr << "SetText.txt could not be opened for reading!" << endl;
- cerr << "Perezagruzi programmu" << endl;
- Sleep(5000);
- exit(1);
- }
- string z1, z2, z3, z4, z5, z6;
- // Пока есть, что читать,
- while (inf)
- {
- // то перемещаем то, что можем прочитать, в строку, а затем выводим эту строку на экран
- string strInput;
- getline(inf, strInput);
- int ci = 0;
- string word = "";
- int probels = 0;
- while ((strInput[ci] != NULL)) {
- strInput[ci];
- if (strInput[ci] != ' ') { word += strInput[ci]; }
- if ((strInput[ci] == ' ')||(strInput[ci+1] == NULL)) { probels++;
- switch(probels) {
- case 1: z1 = word;
- case 2: z2 = word;
- case 3: z3 = word;
- case 4: z4 = word;
- case 5: z5 = word;
- case 6: z6 = word;
- default: word = "";
- }}
- ci++;
- }
- Node *s = getLast();
- if (strInput != "\0") {s = Add(z1, z2, z3, z4, z5, z6, s); }
- }
- Sleep(500);
- //cout << nameFile << " - zagruzhen\nSoderzhanie: " << '"';
- //std::system("pause");
- //return strInput2;
- }
- ///////////////////
- ////////////////
- string List::reedOfFile(string nameFile)
- {
- ifstream inf(nameFile);
- // Если мы не можем открыть файл для чтения его содержимого,
- if (!inf)
- {
- // то выводим следующее сообщение об ошибке и выполняем функцию exit()
- cerr << "SetText.txt could not be opened for reading!" << endl;
- cerr << "Perezagruzi programmu" << endl;
- Sleep(5000);
- exit(1);
- }
- string strInput2;
- // Пока есть, что читать,
- while (inf)
- {
- // то перемещаем то, что можем прочитать, в строку, а затем выводим эту строку на экран
- string strInput;
- getline(inf, strInput);
- strInput2 = strInput2 + strInput;
- }
- Sleep(500);
- cout << nameFile << " - zagruzhen\nSoderzhanie: "<< '"';
- //std::system("pause");
- cout << strInput2;
- cout << '"'<< endl;
- return strInput2;
- }
- ///////////////////
- void List::Swap(Node* node1, Node* Otsenki)
- {
- if (node1 == NULL || Otsenki == NULL) return;
- if (node1 == Otsenki) return;
- if (Otsenki->ptr == node1)
- {
- Node *p = node1;
- node1 = Otsenki;
- Otsenki = p;
- }
- Node *prev1 = Prev(node1);
- Node *prev2 = Prev(Otsenki);
- Node *next1 = Next(node1);
- Node *next2 = Next(Otsenki);
- if (next1 == Otsenki)
- {
- if (prev1 != NULL)
- prev1->ptr = Otsenki;
- else
- head = Otsenki;
- Otsenki->ptr = node1;
- node1->ptr = next2;
- return;
- }
- if (prev1 != NULL)
- prev1->ptr = Otsenki;
- else
- head = Otsenki;
- if (prev2 != NULL)
- prev2->ptr = node1;
- else
- head = node1;
- Otsenki->ptr = next1;
- node1->ptr = next2;
- }
- int main()
- { //setlocate(LC_ALL, "Russian");
- using std::string;
- using std::cin;
- using std::cout;
- using std::getline;
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- system("chcp 1251");
- system("cls");
- List list;
- Otsenki Otsenki;
- list.Print();
- Node *s = list.getLast();
- for (int i = 0; i < 0; i++) {
- string z1;
- string z2;
- string z3;
- string z4;
- string z5;
- string z6;
- cout << ">> N_student ";
- cin >> z1;
- cout << ">> FirstName ";
- cin >> z2;
- cout << ">> LastName ";
- cin >> z3;
- cout << ">> fizika ";
- cin >> z4;
- cout << ">> istoriya ";
- cin >> z5;
- cout << ">> informatika ";
- cin >> z6;
- s = list.Add(z1, z2, z3, z4, z5, z6, s);
- }
- //list.String_total_X();
- //list.reedOfFile("students.txt");
- //list.ValidText("dfgdfgdf1");
- //list.ValidChislo("АА1");
- //list.Delete_end();
- //list.Nomer_s_kontsa_del();
- //list.Del_By_value();
- //list.Print_By_value();
- //list.Delete_prev_end();
- //list.Zamena();
- //list.Zamena_ptr();
- //list.head_next_del();
- //list.Dobav_n_last();
- //list.Dobav_pre_last();
- list.StekOperation();
- //list.WriteFromProgToTxt();
- //list.ReedOfTxtToProg();
- //list.Dobav_head_next();
- //list.HeadToEnd();
- //list.FILO();
- //list.LIFO();
- //cout << "***********************" << endl;
- //list.Print();
- //cout << "Последний элемент: " << list.getValue(list.getLast()) << endl;
- // Удаляем элементы, равные 0
- //Node *p = list.getFirst();
- //do {
- // if (list.getValue(p) == "0")
- // p = list.Delete(p);
- // else
- // p = list.Next(p);
- //} while (p != NULL);
- //list.Print();
- //cout << "В списке " << list.getCount() << " элементов" << endl;
- //list.Swap(list.getFirst(), list.getLast());
- //list.Print();
- //list.Clear();
- list.Print();
- //cout << "В списке " << list.getCount() << " элементов" << endl;
- //cin.get(); cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement