Question & Answer: void addIntToStart0fList(Linked List * list, int value) { assert (list!=NULL);//if list is…..

*list, addIntToStartOfLǐst (Linked List assert (list!=NULL); // if list is NULL, value) do { nothing. void int we can // Add code for this. /I HINTS: // You will need to allocate a new Node // You will need two cases just as in addIntToEnd0fList, // one for when list->head is NULL and another for when it is not // You need to consider how to make sure that list-head // so that it points to the new node that you allocated. // And you will need to make sure that when you are done, /I that if the new node is now the ONLY thing on the list, /I that tail points to it also, / and that the new node is pointing to NULL. // 0therwise, youll need to be sure that when you are done /I the head points to the new node you added, and that / the new node points to the node that used* to be the head // The order in which you do things matters.

void addIntToStart0fList(Linked List * list, int value) { assert (list!=NULL);//if list is NULL, we can do nothing. //Add code for this. //HINTS: //You will need to allocate a new Node. //You will need two cases just as in addIntToEnd0fList, //one for when list- > head is NULL and another for when it is not. //You need to consider how to make sure that list- > head //so that it points to the new node that you allocated. //And you will need to make sure that when you are done, //that if the new node is now the ONLY thing on the list, //that tail points to it also, //and that the new node is pointing to NULL. //Otherwise, you’ll need to be sure that when you are done //the head points to the new node you added, and that //the new node points to the node that *used* to be the head //The order in which you do things matters. }

Expert Answer

 

struct Node {
int data;
struct Node *next;
}

void addIntToStartOfList(LinkedList *list, int value)
{
struct Node *temp;

temp->data = value;

if (list->head == NULL){
list->head = temp;
list->tail = temp;
}
else {

temp->next = list->head;
list->head = temp;
}
}

Still stressed from student homework?
Get quality assistance from academic writers!