Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct node
- {
- int info;
- node * next;
- };
- void setNull(node * & p)
- {
- p = NULL;
- }
- void createElem(node * & p, int y)
- {
- p = new node;
- p->info = y;
- p->next = NULL;
- }
- void addFirst(node * & head1, node * p)//добавление в начало
- {
- p->next = head1;
- head1 = p;
- }
- void addLast(node*&tail,node *q)
- {
- tail ->next = q;
- tail = q;
- }
- void createListFromFile(node * & head1, ifstream & f)
- {
- node * q;
- int x;
- setNull(head1);
- while (f >> x)
- {
- createElem(q, x);
- addFirst(head1, q);
- }
- }
- void setHead(node * head1, node * & p)
- {
- p = head1;
- }
- bool nodeIsNull(node * p)
- {
- return p == NULL;
- }
- void showNode(node * p)
- {
- cout << p->info << ' ';
- }
- void moove(node * & p)
- {
- p = p->next;
- }
- void showList(node * head)
- {
- node * q;
- setHead(head, q);
- if(!nodeIsNull(head))
- while (!nodeIsNull(q))
- {
- showNode(q);
- moove(q);
- }
- else cout << "List is empy";
- cout << endl;
- }
- bool compInfo(node * p1, node * p2)
- {
- return p1->info == p2->info;
- }
- bool taskA(node *head,int E)
- {
- if (nodeIsNull(head))
- return false;
- else
- {
- if (head->info == E)
- return true;
- taskA(head->next, E);
- }
- }
- void taskB(node *head, int E, int&k)
- {
- if (!nodeIsNull(head))
- {
- if (head->info == E)
- k++;
- taskB(head->next, E,k);
- }
- }
- int taskC(node *head, int max)
- {
- if (nodeIsNull(head))
- return max;
- else
- {
- if (head->info > max)
- max = head->info;
- taskC(head->next, max);
- }
- }
- void taskD(node *head)
- {
- if (!nodeIsNull(head))
- {
- taskD(head->next);
- showNode(head);
- }
- }
- void taskE(node *head,int e1, int e2)
- {
- if (!nodeIsNull(head))
- {
- if (head->info == e1)
- head->info = e2;
- taskE(head->next,e1,e2);
- }
- }
- void taskF(node *&head, int e1, node*temp)
- {
- if (!nodeIsNull(head))
- {
- if (head->info != e1)
- {
- temp = head;
- taskF(head->next, e1,temp);
- }
- else
- {
- if (temp == head)
- head = head->next;//первый элемент
- else
- temp->next = head->next;
- }
- }
- }
- void taskG(node *&head, int e1, node*temp)//
- {
- if (!nodeIsNull(head))
- {
- if (head->info == e1)
- {
- if (temp == head)
- head = head->next;//первый элемент
- else
- temp->next = head->next;
- }
- temp = head;
- taskG(head->next, e1, temp);
- }
- }
- void taskH(node* &head1, node*&head2, node*&tail)
- {
- node*p;
- if(!nodeIsNull(head1))
- {
- createElem(p, head1->info);
- addLast(tail, p);
- taskH(head1->next, head2, tail);
- }
- }
- void taskI(node* &head1, int e1)
- {
- if (!nodeIsNull(head1))
- {
- if (head1->info == e1)
- {
- node*p;
- createElem(p, e1);
- p->next= head1->next;
- head1->next = p;
- taskI(p->next, e1);
- }
- else
- taskI(head1->next, e1);
- }
- }
- void sr(node*&head, double &s, int &k)//не пустой список
- {
- if (!nodeIsNull(head))
- {
- s += head->info;
- k++;
- sr(head->next, s, k);
- }
- else
- cout<< s / k;
- }
- int main()
- {
- ifstream f("Text.txt");
- node * head1;
- createListFromFile(head1, f);
- showList(head1);
- /*if (!nodeIsNull(head1))
- {
- int e;
- cin >> e;
- taskA(head1, e) ? cout << "YES" : cout << "NO";
- cout << endl;
- }
- else cout << "List is empy" << endl;*/
- if (!nodeIsNull(head1))
- {
- int e,k=0;
- cin >> e;
- taskB(head1, e,k);
- cout <<k<< endl;
- }
- else cout << "List is empy" << endl;
- //cout << taskC(head1, head1->info) << endl;
- /*if (!nodeIsNull(head1))
- {
- taskD(head1);
- cout << endl;
- }
- else cout << "List is empy" << endl; */
- /*if (!nodeIsNull(head1))
- {
- int e1, e2;
- cin >> e1 >> e2;
- taskE(head1, e1, e2);
- showList(head1);
- }
- else cout << "List is empy" << endl;*/
- /*if (!nodeIsNull(head1))
- {
- int e1;
- cin >> e1;
- taskF(head1, e1,head1);
- showList(head1);
- }
- else cout << "List is empy" << endl;*/
- /*if (!nodeIsNull(head1))
- {
- node* head2 = new node;
- setNull(head2->next);
- head2->info = head1->info;
- moove(head1);
- node* tail = head2;
- taskH(head1, head2, tail);
- showList(head2);
- }
- else cout << "List is empy" << endl;*/
- /*if (!nodeIsNull(head1))
- {
- int e1;
- cin >> e1;
- taskI(head1, e1);
- showList(head1);
- }
- else cout << "List is empy" << endl;*/
- /*double s = 0;int k = 0;
- sr(head1, s, k);*/
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment