include iostream include fstream include stdio using namespace std str

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
struct ListElem{
ListElem* next;
ListElem* prev;
char value;
};
class List {
private:
ListElem* head;
public:
List() { // конструктор
head = NULL;
}
List(ListElem* head) {
this->head = head;
}
~List() { // деструктор
ListElem* tek = head;
while (tek) {
ListElem* next = tek->next;
delete tek;
tek = next;
}
}
ListElem* copy() {
ListElem* tek = head;
ListElem* new_list = new ListElem;
ListElem* new_head = new_list;
ListElem* prev = NULL;
while (tek) {
new_list->value = tek->value;
new_list->prev = prev;
prev = new_list;
if (tek->next)
new_list->next = new ListElem;
else
new_list->next = NULL;
tek = tek->next;
new_list = new_list->next;
}
return new_head;
}
void PushBack(char value) {
if (head == NULL) {
head = new ListElem;
head->value = value;
head->next = NULL;
head->prev = NULL;
return;
}
ListElem* tek = head;
while (tek->next) {
tek = tek->next;
}
ListElem* new_elem = new ListElem;
new_elem->value = value;
new_elem->next = NULL;
new_elem->prev = tek;
tek->next = new_elem;
}
void Print(ofstream &outfile) {
ListElem* tek = head;
while (tek) {
outfile << tek->value;
tek= tek->next;
}
outfile << endl;
}
void Check(char c) {
ListElem* tek = head;
while (tek->next) {
if (tek->next->value == c) {
if (tek->prev) {
tek->prev->next = tek->next;
}
tek->next->prev = tek->prev;
ListElem* next = tek->next;
delete tek;
tek = next;
} else {
tek = tek->next;
}
}
}
};
int main() {
List my_list;
FILE * pFile = fopen("input.txt", "r");
if (pFile==NULL) cout << "Error opening file" << endl;
else {
cout << "Reading input data..." << endl;
int c;
while ((c = getc(pFile)) != EOF) {
my_list.PushBack((char)c);
}
fclose(pFile);
}
char symbol;
cin >> symbol;
List new_list(my_list.copy());
new_list.Check(symbol);
ofstream file1("out_full.txt");
my_list.Print(file1);
ofstream file2("out_clean.txt");
new_list.Print(file2);
return 0;
}