Question: Complete construct_3.c to build the structure in the above drawing. For convenience, you may use temporary pointers in addition to x. Your implementation must pass
Complete construct_3.c to build the structure in the above drawing. For convenience, you may use temporary pointers in addition to x. Your implementation must pass the self-contained tests (you do not have to implement it). For instance, when you run
./construct_3
The self-test should output:
x -> 1
1 -> 2
2 -> 3
3 -> 1

1 2 construct_3.c X 1 #include 2 #include 3 typedef struct node { 4 int value; 5 struct node* next; 6 - } node_t; 7 8 Enode_t * construct_3() { 9 //Allocate three pointers: 10 //x for the first Node, and temporary pointers y and z for the other two Nodes. 11 12 //Allocate three Node pins, and store references to them in the three pointers. 13 14 / /Dereference each pointer to store the appropriate number into the value field in its paintes 15 16 //Dereference each pointer to access the .next field in its printre 17 //and use pointer assignment to set the .next field to point to the appropriate Node. 18 19 } 20 21 //You can ignore the following code for testing 22 int dump_all (node_t*); 23 Qint main (int arge, char ** argv) { 24 25 node_t x = construct_3(); 26 return dump_all(x); 27 28 } 29 30 Fint dump_all (node_t * x) { 31 printf("x -> %d ", x->value); 32 node_t y = x->next; 33 printf("%d -> $d ", x->value, y->value); 34 node_t * z = y->next; 35 printf("%d -> $d ", y->value, z->value); 36 if (z->next != x) { 37 printf("failed"); return -1; 39 } else { 40 printf("%d -> %d ", z->value, x->value); 41 return 0; 42 43 44 38