Runtime error happens when deleting a node of the linklist : <p>Here's my C++ code of a simple structured linklist.</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

class Node{
public:
    int data;
    Node* next;
    Node* prev;
    Node(){
        data=-1;
        next=NULL;
        prev=NULL;
    }
    Node(int d,Node *nnext){
        data=d;
        next=nnext;
    }
    void add(Node* nnext){
        next=nnext;
        nnext-&gt;prev=this;
    }

};
void print(Node*  head){
    Node* cNode;
    cNode=head;
    while (cNode!=NULL){
        cout &lt;&lt;"["&lt;&lt;cNode-&gt;data&lt;&lt;"]" &lt;&lt; endl;
        cNode=cNode-&gt;next;
    }
}
void insertAfter(Node* pNode, Node* nNode){
    nNode-&gt;next = pNode-&gt;next;
    pNode-&gt;next = nNode;
    pNode-&gt;next-&gt;prev = nNode;

}
void deleteNode(Node* b){

    Node* c=b-&gt;next;
    Node* a=b-&gt;prev;
    a-&gt;next=c;
    c-&gt;prev=a;
    delete b;

}
void main(){
    Node* head;
    head=new Node();
    head-&gt;data=1;
    Node * currentNode=head;
    for (int i=2;i&lt;=5;i++){
        Node* nNode=new Node(i,NULL);
        currentNode-&gt;add(nNode);
        currentNode=nNode;
    }
    cout &lt;&lt; currentNode-&gt;data &lt;&lt; endl;
    print(head);
    insertAfter(head, new Node(99,NULL));
    //deleteNode(currentNode);
    print(head);

}
</code></pre>

<p>The case checking is unnecessary because I just need the concept of the linklist. If you have another version of these kind of simple linklist code, please let me know! Thank you!</p>
