check-C-Code-And-Explain-What-It-Does-And-Also-Check-For-Errors-programming-homework-help

*Note*: You do not need to use a programming application to complete these questions as they contain only parts of a program. You should be able to complete these questions in 20 minutes.

Question 1: Consider the following program fragment that defines a self‐referential type:

#include <stdbool.h>


#include <stdlib.h>





struct dnode_int;



typedef struct dnode_int *dnode;



struct dnode_int



{



dnode prev;



void *data;



dnode next;



};



typedef struct roundabout_int {dnode cursor;} *roundabout;



…



int f1(roundabout r)
//Comment here



{



dnode c=r->cursor;
//Comment here



int s=0;
//Comment here









while (c != NULL)
//Comment here




{



s++; c=c->prev;
//Comment here




}



return s;
//Comment here




}







a) What does the function
f1() do (or should do if it were free of errors)? In 1-2 sentences, replace the “Comment here” within the
f1() function with a explanation of what that line of code does. Also include references to other parts of the code if necessary.



b) Describe possible problems with the code of the function
f1().

_________________________________________________________________________________________________

Question 2: Consider the following program fragment that defines a self‐referential class:

#include <stdbool.h>


#include <stdlib.h>





struct node_int;



typedef struct node_int *node;



struct node_int



{



void *data;



bool empty;



node next;



};



typedef struct list_int {node first;} *list;



…



bool f2(list ell)
//Comment here




{



node c=ell;
//Comment here




int r=0;
//Comment here








while (c != NULL)
//Comment here




{



if (! c->empty)
//Comment here




{



r++;
//Comment here




}



c=c->next;
//Comment here




}



return (r == 0);
//Comment here







}


a) What does the function
f2() do (or should do if it were free of errors)? In 1-2 sentences, replace the “Comment here” within the
f2() function with a explanation of what that line of code does. Also include references to other parts of the code if necessary.


b) Describe possible problems with the code of the function
f2().

 
Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code "Newclient" for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.