Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct node
- {
- char info;
- node * next;
- };
- void setNull(node * & p)
- {
- p = NULL;
- }
- void createElem(node * & p, char y)
- {
- p = new node;
- p->info = y;
- p->next = NULL;
- }
- void addFirst(node * & head1, node * p)//добавление в начало
- {
- p->next = head1;
- head1 = p;
- }
- 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 createListFromFile(node * & head1, ifstream & f)
- {
- node * q;
- char x;
- head1 = new node;
- setNull(head1->next);
- node* tail = head1;
- while (f.get(x))
- {
- createElem(q, x);
- tail->next = q;
- tail = q;
- }
- q = head1;
- moove(head1);
- delete q;
- }
- void showList(node * head)
- {
- node * q;
- setHead(head, q);
- while (!nodeIsNull(q))
- {
- showNode(q);
- moove(q);
- }
- cout << endl;
- }
- void Del(node *& head)
- {
- node * q,*temp;
- bool t;
- setHead(head, q);
- while (!nodeIsNull(q))
- {
- if (q->info == ' ')
- {
- t = false;
- temp = q;
- moove(q);
- while (!nodeIsNull(q)&&q->info != ' ')
- {
- if (q->info == 'f')
- t = true;
- moove(q);
- }
- if (t)
- temp->next = q;
- }
- else
- {
- t = false;
- while (!nodeIsNull(q) && q->info != ' ')
- {
- if (q->info == 'f')
- t = true;
- moove(q);
- }
- if (t)
- head = q;
- }
- }
- }
- int main()
- {
- ifstream f("Text.txt");
- node * head1;
- createListFromFile(head1, f);
- showList(head1);
- Del(head1);
- showList(head1);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement