Note that there are some explanatory texts on larger screens.

plurals
  1. POPrint an ordered linked list
    primarykey
    data
    text
    <p>Just did some editing on it, i tried what you said but it didnt work, so i tried something i am a little more familiar with but it doesnt seem to work correctly. It prints the information weirdly then crashes.. For exmaple: When i imput 9-8-7-6-5-4-3-2-1 then 0 to print, it prints back to me 0-0-0-9-1-2-3-4-5-6-7-8 and then crashes? when i imput 1-2-3-4-5-6-7-8-9 then 0 to print, it prints back to me 0-0-0-1-2-3-4-5-6-7-8-9 and then crashes.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; struct listNode{ int data; //ordered field struct listNode *next; }; //prototypes void insertNode(struct listNode *Head, int x); int printList(struct listNode *Head); int freeList(struct listNode *Head, int x); //main int main(){ struct listNode Head = {0, NULL}; int x = 1; int ret = 0; printf("This program will create an odered linked list of numbers greater" " than 0 until the user inputs 0 or a negative number.\n"); while (x &gt; 0){ printf("Please input a value to store into the list.\n"); scanf("%d", &amp;x); insertNode(&amp;Head, x); } ret = printList(&amp;Head); } void insertNode(struct listNode * Head, int x){ struct listNode *newNode, *current; newNode = malloc(sizeof(struct listNode)); newNode-&gt;data = x; newNode-&gt;next = NULL; current = Head; while (current-&gt;next != NULL &amp;&amp; current-&gt;data &lt; x) { current = current-&gt;next; } if(current-&gt;next == NULL){ current-&gt;next = newNode; } else{ newNode-&gt;next = current-&gt;next; current-&gt;next = newNode; } } int printList(struct listNode * Head){ struct listNode *current = Head; while (Head != NULL){ printf("%d \n", *current); current = current-&gt;next; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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