Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct node
- {
- int info;
- node *next;
- };
- void create_listFile(node *&head, ifstream &f)
- {
- head = NULL;
- int info = 0;
- while (f >> info)
- {
- node *q = new node;
- q->info=info;
- q->next = head;
- head = q;
- }
- }
- bool blank(node * head)
- {
- return head == NULL;
- }
- void show_list(node* head)
- {
- if (blank(head))
- cout << "Пусто" << endl;
- else
- {
- node* q = head;
- while (q!=NULL)
- {
- cout << q->info << ' ';
- q = q->next;
- }
- cout << endl;
- }
- }
- void deletFirstEl(node *&head)//A
- {
- node *p = head;
- head = head->next;
- p->next = NULL;
- delete p;
- }
- void deletSecondEl(node *&head)//Б
- {
- node *q = head;
- node *p = new node;
- if (blank(head))
- cout << "Пусто" << endl;
- else
- {
- if (head->next == NULL)
- cout << "Короткий список" << endl;
- else
- {
- p = q->next;
- q->next = q->next->next;
- show_list(head);
- }
- }
- }
- void B(node *&head, int x)//B
- {
- node *q = head;
- node *p = new node;
- if (blank(head))
- cout << "Пусто" << endl;
- else
- {
- while (q != NULL)
- {
- if (q->info == x&& q->next != NULL)
- {
- p = q->next;
- q->next = q->next->next;
- }
- q = q->next;
- }
- show_list(head);
- }
- }
- void endelemet(node *&head)//Г
- {
- node *q = head;
- node *p = new node;
- if (blank(head))
- cout << "Пусто" << endl;
- else
- {
- if (head->next== NULL)
- {
- head = NULL;
- q = q->next;
- delete q;
- }
- else
- {
- while (q->next->next != NULL)
- q = q->next;
- p = q->next;
- q->next = NULL;
- delete p;
- }
- show_list(head);
- }
- }
- void D(node *&head)
- {
- node *q = head;
- node *p = new node;
- if (blank(head))
- cout << "Пусто" << endl;
- else
- {
- if (head->next == NULL)
- {
- if (q->info < 0)
- {
- head = NULL;
- q = q->next;
- delete q;
- }
- }
- else
- {
- if (q->info < 0)
- head = q->next;
- else
- {
- while (q != NULL && q->info > 0)
- {
- p = q;
- q = q->next;
- }
- if (q != NULL && q->info < 0)
- {
- p->next = q->next;
- q->next = NULL;
- delete q;
- }
- }
- }
- show_list(head);
- }
- }
- void E(node *&head)
- {
- node *q = head, *mark = head;
- node *p = new node;
- if (blank(head))
- cout << "Пусто" << endl;
- else
- {
- if (head->next == NULL)//список из одного элемента
- {
- if (q->info < 0)
- {
- head = NULL;
- q = q->next;
- delete q;
- }
- }
- else
- {
- while (q->info < 0)
- {
- head = q->next;
- q = head;
- }
- while (q != NULL)
- {
- if (q->info < 0)
- {
- mark->next = q->next;
- q->next = NULL;
- q=mark->next;
- }
- else
- {
- mark = q;
- q = q->next;
- }
- }
- }
- show_list(head);
- }
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- node * head = NULL;
- ifstream in("Text.txt");
- create_listFile(head, in);
- show_list(head);
- //deletFirstEl(head);//A
- //deletSecondEl(head);//Б
- //B(head, 3);//B
- //endelemet(head);//Г
- //D(head);
- E(head);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment