[ create a new paste ] login | about

Link: http://codepad.org/TzzkiniO    [ raw code | fork ]

C++, pasted on Mar 20:
struct node {
    char info;
    node* next;
    node(char a = 0, node* b = 0) {
        info = a;
        next = b;
    }
};

void g(node* L, int k, char y) {
    node* current = L;
    if (current->info == y) k--;
    while (current->next) {
        if (current->next->info == y) {
            if (k > 0) k--;
            else {
                node* very_next = current->next->next;
                delete current->next;
                current->next = very_next;
            }
        }
        current = current->next;
    }
}

int main() {
    node* n = new node('a',new node('b', new node('a', new node('c', new node('a', 0)))));
    g(n, 10, 'a');
    n = new node('a',new node('b', new node('a', new node('c', new node('a', 0)))));
    g(n, 10, 'b');
    n = new node('a',new node('b', new node('a', new node('c', new node('a', 0)))));
    g(n, 10, 'c');
    n = new node('a',new node('b', new node('a', new node('c', new node('a', 0)))));
    g(n, 10, 'q');
}


Output:
No errors or program output.


Create a new paste based on this one


Comments: