Предлагаю свою реализациюstruct Item {
Item(): next(NULL), c('\0') {
}
char c;
Item *next;
};
struct List {
List(const char* in_str) : item(NULL){
unsigned size = strlen(in_str);
item = new Item[size];
for (unsigned i(0); i < size; ++i) {
item[i].c = in_str[i];
if (i) {
item[i-1].next = &item[i];
}
}
}
~List() {
delete[] item;
}
void remove(char in_) {
Item* it = item;
while (it) {
if (it->c == in_) {
*it = *it->next;
}
if (it->next) {
if (it->c != in_) {
it += (it->next - it);
}
} else {
if (it->c == in_) {
it->c = '\0';
}
break;
}
}
}
const char* takeString() {
const unsigned size = 255;
char str[size];
Item* it = item;
char* ptrstr = (char*)&str;
memset(&str, '\0', size);
while (it) {
*ptrstr = it->c;
if (!it->next) {
break;
}
if (it->next) {
it += (it->next - it);
++ptrstr;
} else {
break;
}
}
return str;
}
Item* item;
};
int main()
{
List list(" bla1 bla2 bla3 ");
list.remove(' ');
printf("\n begin[%s%s\n", list.takeString(), "]end");
return 0;
}