Question: Skeleton Code: Run the following command in the code server: cp / usr / local / share / csc 2 5 0 / sophia /

Skeleton Code: Run the following command in the code server:
cp /usr/local/share/csc250/sophia/a5Skeleton.c.
Assignment:
Using the provided skeleton code, write the following functions below for a linked
list program:
a. insertMiddle()- insert a node at a specified index in the middle of the linked
list
b. deleteMiddle()- delete a node at a specified index in the middle of the
linked list
c. deleteList()- delete the entire linked list
d. deleteValue()- delete a node with a specified value in the linked list
Utilizing these functions, do the following in order:
a. Insert the value 99 at index 5 of the linked list
i. Print out the new list
b. Insert the value 32 at index 7 of the linked list
i. Print out the new list
c. Delete the node at index 3
i. Print out the new list
d. Delete the value of 10 from the linked list
i. Print out the new list
e. Delete the entire linked list
i. Print out the result
Note: You may choose the parameters to pass into these functions.
Print out the list after every insertion or deletion operation.
Skeleton code
#include
#include
//Define node structure - written in class
typedef struct node{
int data;
struct node* next;
}node;
//Print entire list - written in class
void printList(node *head)
{
node *current;
current = head;
//printf("---- LIST ----
");
while(current != NULL)
{
printf("%d ", current->data);
current = current->next;
}
printf("
");
}
//Insert node at beginning of the list - written in class
node *insertFront(node *head, int val)
{
node *newNode;
newNode = malloc(sizeof(node));
newNode->data = val;
newNode->next = NULL;
if(head == NULL)
{
head = newNode;
}else
newNode->next = head;
return newNode;
}
//Insert node at end of list - writen in class
void insertBack(node *head, int val)
{
node *newNode;
newNode = malloc(sizeof(node));
newNode->data = val;
newNode->next = NULL;
node *current;
current = head;
while(current->next != NULL)
{
current = current->next;
}
current->next = newNode;
}
//Delete node at front of list - written in class
node *deleteFront(node *head)
{
node *current;
current = head;
head = head->next;
printf("deleting %d
", current->data);
free(current);
return head;
}
//Delete node at end of list - written in class
void deleteBack(node *head)
{
node *current;
current = head;
while(current->next->next != NULL)
{
current = current->next;
}
printf("deleting %d
", current->next->data);
free(current->next);
current->next = NULL;
}
//Insert a node at a specified index in the middle of list
void insertMiddle()
{}
//Delete a node at a specified index in the middle of list
void deleteMiddle()
{}
//Delete the entire list
void deleteList()
{}
//Delete the node containing a specified value in list
void deleteValue()
{}
int main()
{
//--DO NOT CHANGE THIS SECTION--//
//Create and initialize head pointer
node *head = NULL;
//~~~~Insert Nodes~~~~//
head = insertFront(head,42);
head = insertFront(head,37);
head = insertFront(head,235);
head = insertFront(head,877);
head = insertFront(head,88);
head = insertFront(head,401);
head = insertFront(head,323);
head = insertFront(head,461);
head = insertFront(head,784);
head = insertFront(head,358);
insertBack(head,12);
insertBack(head,713);
insertBack(head,209);
insertBack(head,466);
insertBack(head,55);
insertBack(head,10);
insertBack(head,515);
insertBack(head,2);
insertBack(head,75);
insertBack(head,199);
//Print the list
printf("--Initial List--
");
printList(head);
//--END OF SECTION--//
//Insert the value 99 at index 5 of the linked list (using insertMiddle())
//Print the list
printf("--List after inserting 99 at index 5--
");
//Insert the value 32 at index 7 of the linked list (using insertMiddle())
//Print the list
printf("--List after inserting 32 at index 7--
");
//Delete the node at index 3(using deleteMiddle())
//Print the list
printf("--List after deleting index 3--
");
//Delete the node holding the value of 10 from the inked list (using deleteValue())
//Print the list
printf("--List after deleting value 10--
");
//Delete the entire list (using deleteList())
//Print the list
printf("--Result of deleting entire list--
");
return 0;
}
Skeleton Code: Run the following command in the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!