Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Now I can see all the code the problem is very simple. Your deletebeg function is deleting the beginning node with <code>delete</code>, but you didn't allocate the node with <code>new</code>. You should only <code>delete</code> memory if you created it using <code>new</code>.</p> <p>Normally when people write linked list classes they allocate the nodes inside the list methods using <code>new</code>. Then they can safely <code>delete</code> the nodes inside the methods. You are doing the deletes but you are not using new. So you need to rewrite your main function like this</p> <pre><code>int main() { doublelist list1; list1.insertbeg(8); // add 8 to beginning of list list1.insertbeg(7); // add 7 to beginning of list list1.insertafter(4,1); // add 4 after first item of list list1.insertend(9); // add 9 to end of list list1.deletebeg(); } </code></pre> <p>Then you need to rewrite your methods like this</p> <pre><code>void insertbeg(int value)//insert beginning { nodeb* a = new nodeb(value); // allocate node inside of method using new if(head1==0) { head1=a; head2=a; a-&gt;next=0; a-&gt;pre=0; } else { nodeb *ptr=head1; ptr-&gt;pre=a; a-&gt;pre=0; a-&gt;next=ptr; head1=a; } } </code></pre> <p>I've only shown insertbeg, you need to change all your insert methods in the same way. </p> <p>I'm not promising that's the only problem, but make this change and you'll be on the right way. If you have more problems then post again, but remember <strong>post complete code</strong>. It's the only way you'll get help with problems like this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload