Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In this line:</p> <pre><code>struct node*p; </code></pre> <p>it should be</p> <pre><code>struct node p; </code></pre> <p>you're creating pointer to node. But don't initialize it later, so no node is created and it points to random location. Then you pass that as argument to your functions.<br> When you are dereferencig this pointer in your functions <code>p-&gt;</code> you have a segmentation fault. <br><br> In your <code>main</code> function you should have declaration of 'node', not <code>pointer to node</code>, and then pass node's address to function with <code>&amp;</code> operator.<br><br> So your function declaration <code>void addatbeg(struct node *p,int num);</code> is fine but it should be called (after you declare node p):</p> <pre><code>addatbeg(&amp;p,some_number); </code></pre> <p>Also, every function that makes use of p should be changed to treat p like a structure, not like pointer to structure.<br><br> What you did here is confused some information on linked lists.<br> Usually head of a <code>singly linked list</code> declared as a pointer to node. When I implemented sll myself I did that, too. Then you pass that pointer by reference to functions manipulating on linked list and it works fine.<br> On the other hand you got <code>doubly linked lists</code>, and there it is more convinient to treat head of <code>doubly linked list</code> as just another node, but without value.<br> You are trying to mix those ideas together without understanding ideas behind them. <br> I gave you bunch of tips on how to make it work, but fixing it would mean that I have to rewrite your whole code.<br><br> And that's not the point since you should learn it yourself.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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