There are two blank functions below that you should complete based on the requirements described as comments inside the function. To test your function you may or may not need to uncomment/add lines...


There are two blank functions below that you should complete based on the requirements described as comments inside the function. To test your function you may or may not need to uncomment/add lines in the main function. Compare your result with the comment given in main function.  Copy the whole code (all complete and incomplete functions, including comments, libraries) into your own text editor or preferred IDE.

Start completing the code based on the question requirements.
After completing the code and testing, submit the modified ".c" code before the due time as the answer in the quiz.






#include
#include

typedef struct node{
int info;
struct node *next;
}node;


node* SortInsert(node *root, int item); //this function is complete
void simplePrint(node* root); //this function is complete
int sumMyList(node* root); //you have to write this function, see below //total grade 50
node* BackToFrontMove (node * root); //you have to write this function, see below // total grade 50





int main()
{
node* head=NULL;
node* head2 = NULL;



node *t;
int ch,ele;
head = SortInsert(head, 4);
head = SortInsert(head,6);
head = SortInsert(head,3);
head = SortInsert(head,5);



printf("\nSimple print List 1: ");
simplePrint(head);



printf("\nsum of the list %d", sumMyList(head)); //modify the sumMyList function to make it work. It should print 18.



head = BackToFrontMove(head);//modify the BackToFrontMove function to make it work
printf("\nSimple print: "); //it should print 6, 3, 4, 5
simplePrint(head);




return 0;


}


void simplePrint(node* root)
{
node* t=root;
while(t!=NULL)
{
printf("%d ",t->info);
t=t->next;
}
}


node* SortInsert(node* root, int item)
{
node *temp;
node *t;
temp= (node *) malloc(sizeof(node));
temp->info=item;
temp->next=NULL;
if (root==NULL || root->info >=item)
{
temp->next = root;
root = temp;
}
else
{
t = root;
while (t->next != NULL && t->next->info t = t->next;
temp->next = t->next;
t->next = temp;
}



return root;
}


///////// All questions are starting here//////////////////




int sumMyList(node* root)
{
/*this function takes the head of a linked list and return the sum of all the data in the linked list. using loops is totally fine, however, if you want you can write a recursive function.
*/



return -1; //this is a dummy return. Remove it when you write your function.




};




node* BackToFrontMove (node * root)
{
/*this function takes the head of a linked list and move the tail node's item in the linked list to the head
and return the new head. Example: Linked list 3, 4, 5, 6 will be changed to 6, 3, 4, 5
At the end, the function returns the head*/




return NULL; //this is a dummy line. Remove this line when you write your code.


}


Jun 18, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here