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;
}
}