struct List
{
char c;
List *next;
};
List *delSpaces(List *p)
{
p = delSpace(p);
List *head = p;
while (p)
{
p->next = delSpace(p->next);
p = p->next;
}
return head;
}
List *delSpaces(List *p) {
while (p && p->c == ' ')
{
p = p->next;
}
struct L *head = p;
struct L *prev = p;
p = p->next;
while (p)
{
if (p->c == ' ')
{
prev->next = p->next;
}
else
{
prev = p;
}
p = p->next;
}
return head;
}
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;
}