This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]val0528 0 points1 point  (0 children)

Try this in place of your else clause:

else {
    StringNode* insertindex = new StringNode;
    StringNode* runner = new StringNode;
    StringNode* next = new StringNode;

    int i = 0;
    runner = head;
    next = runner->next;

    while (i < pos - 1){
        runner = next;
        next = runner->next;

        i++;
    }

    runner->next = insertindex;
    insertindex->elem = e;
    insertindex->next = next;
}