Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- struct list
- {
- char data; //pole dannih
- int numb; //pole nomera elementa
- list *link;//pole adresa
- };
- list *sozdspis(char, int, list*);
- list *addelem(char, char, list*);
- void viewsp(list*);
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int i = 1;
- list *first = NULL;
- char ch, E;
- cout << "n Вводите элементы списка сплошной строкой; "
- "n в конце - точка: n";
- cin >> ch;
- while (ch != '.')
- {
- first = sozdspis(ch, i, first);
- i++;
- cin >> ch;
- }
- cout << "Введите элемент E n";
- cin >> E;
- first = addelem(E, ch, first);
- if (first != NULL)
- {
- cout << "Результат получен n";
- viewsp(first);
- }
- else cout << "Результата нетn";
- cin.get();
- system("pause");
- return 1;
- }
- list * addelem(char E, char ch, list *first)
- {
- list *temp, *p, *now = first;
- while ((now != NULL) && (now->data))
- {
- now = now->link;
- if (now->data == E) //все что я смог придумать D:
- {
- now->link = temp;
- temp->data = E;
- temp->link = now;
- }
- }
- return temp;
- }
- //viewsp Begin______________________________
- //Просмотр циклического списка
- void viewsp(list *head)
- {
- list *tec = head;
- do
- {
- cout << tec->data;
- tec = tec->link;
- } while (tec != head);
- }
- //viewsp End___________________________________________________________________
- //sozdspis Begin_______________________________________________________________
- //Добавление нового элемента в список
- list *sozdspis(char ch, int k, list *head)
- {
- list *tec,
- *nov = new(list);
- nov->data = ch;
- nov->numb = k;
- nov->link = NULL;
- if (head) //список не пуст
- {
- tec = head;
- while (tec->link)
- tec = tec->link;
- tec->link = nov;
- }
- else //список пуст
- head = nov;
- return head;
- }
Add Comment
Please, Sign In to add comment