val val > val)1011break;12succ = succ->next;13}struct node * this = malloc(sizeof (struct node));this->val = val;141516this->next = succ;17if (pred != NULL) {pred->nextreturn first;}...


Question 1<br>The code below defines a singly-linked list. This consists of the following definition of<br>node:<br>1<br>struct node {<br>int val;<br>struct node * next;<br>4 }<br>Also, it uses the following insert function:<br>struct node * insert(struct node * first, const int val) {<br>6<br>struct node * pred = NULL, *<br>succ = first;<br>7<br>while (succ != NULL) {<br>8<br>if (succ->val < val)<br>pred = succ;<br>if (succ->val > val)<br>10<br>11<br>break;<br>12<br>succ = succ->next;<br>13<br>}<br>struct node * this = malloc(sizeof (struct node));<br>this->val = val;<br>14<br>15<br>16<br>this->next = succ;<br>17<br>if (pred != NULL) {<br>pred->next<br>return first;<br>} else {<br>18<br>this;<br>%3D<br>19<br>20<br>21<br>return this;<br>22<br>}<br>23 }<br>Note that the code above compiles correctly.<br>(a) Give an implementation in C for a function that prints all values in the singly-linked<br>starting from the first node and following the next node one by one along the list.<br>Use the following signature:<br>void print (struct node * first);<br>

Extracted text: Question 1 The code below defines a singly-linked list. This consists of the following definition of node: 1 struct node { int val; struct node * next; 4 } Also, it uses the following insert function: struct node * insert(struct node * first, const int val) { 6 struct node * pred = NULL, * succ = first; 7 while (succ != NULL) { 8 if (succ->val < val)="" pred="succ;" if="" (succ-="">val > val) 10 11 break; 12 succ = succ->next; 13 } struct node * this = malloc(sizeof (struct node)); this->val = val; 14 15 16 this->next = succ; 17 if (pred != NULL) { pred->next return first; } else { 18 this; %3D 19 20 21 return this; 22 } 23 } Note that the code above compiles correctly. (a) Give an implementation in C for a function that prints all values in the singly-linked starting from the first node and following the next node one by one along the list. Use the following signature: void print (struct node * first);

Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here