Note that there are some explanatory texts on larger screens.

plurals
  1. PONodes deleting after being printed
    primarykey
    data
    text
    <p>So I'm trying to write a program that does a couple different operates on a set of nodes I've built. However, it seems whenever I generate the nodes, then print them, they get lost or deleted. My code is as follows:</p> <pre><code>void insertNodeAtTail(DlistRef dl, Info g){ /* insert a new node at the end of the list with value g */ NodeRef n = initializeNode(g); if (dl-&gt;head == NULL){ //Empty list case dl-&gt;tail = n; dl-&gt;head = n; } else { //Not empty list case n-&gt;prev = dl-&gt;tail; dl-&gt;tail-&gt;next = n; dl-&gt;tail = n; } }/*insertNodeAtTail*/ void insertNodeAtHead(DlistRef dl, Info g){ /* insert a new node with value g at the beginning of the list */ NodeRef n = initializeNode(g); if (dl-&gt;head == NULL){ //Empty list case dl-&gt;head = n; dl-&gt;tail = n; }else{ //Not empty list case n-&gt;next = dl-&gt;head; dl-&gt;head-&gt;prev = n; dl-&gt;head = n; }/*if+else*/ }/*insertNodeAtHead*/ void printListForward(DlistRef dl, char* title){ /* print list items in forward order starting at head */ /* title can be used to add a descriptive title for the list output */ if (dl-&gt;head == NULL){ printf("Empty list\n"); } /*if*/ while (dl-&gt;head != NULL){ printf("%d ", dl-&gt;head-&gt;item-&gt;info); dl-&gt;head = dl-&gt;head-&gt;next; }/*while*/ }/*printListForward* int main(){ char string[] = "myList"; DlistRef dl = initializeDlist(); int i; for(i=0; i &lt;= 15; i++){ if(i%2 != 0){ insertNodeAtTail(dl,i); } } printf("Forward: "); printListForward(dl, string); insertNodeAtHead(dl, 0); insertNodeAtTail(dl, 17); printf("\n"); printf("Forward: "); printListForward(dl, string); return EXIT_SUCCESS; } </code></pre> <p>I suspect it is in my insertNodeAtTail function, where I've forgot to link something. The output of my program here is:</p> <p>Forward: 1 3 5 7 9 11 13 15 Forward: 0 17</p> <p>It should append 0 and 17 to the front and back respectively, making the 2nd set go to: Forward: 0 1 3 5 7 9 11 13 15 17.</p> <p>Thanks :)</p>
    singulars
    1. This table or related slice is empty.
    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. 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