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 usrlocalsharecscsophiaaSkeleton.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 at index of the linked list
i Print out the new list
b Insert the value at index of the linked list
i Print out the new list
c Delete the node at index
i Print out the new list
d Delete the value of 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 printListnode head
node current;
current head;
printf LIST
;
whilecurrent NULL
printfd currentdata;
current currentnext;
printf
;
Insert node at beginning of the list written in class
node insertFrontnode head int val
node newNode;
newNode mallocsizeofnode;
newNodedata val;
newNodenext NULL;
ifhead NULL
head newNode;
else
newNodenext head;
return newNode;
Insert node at end of list writen in class
void insertBacknode head int val
node newNode;
newNode mallocsizeofnode;
newNodedata val;
newNodenext NULL;
node current;
current head;
whilecurrentnext NULL
current currentnext;
currentnext newNode;
Delete node at front of list written in class
node deleteFrontnode head
node current;
current head;
head headnext;
printfdeleting d
currentdata;
freecurrent;
return head;
Delete node at end of list written in class
void deleteBacknode head
node current;
current head;
whilecurrentnextnext NULL
current currentnext;
printfdeleting d
currentnextdata;
freecurrentnext;
currentnext 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 insertFronthead;
head insertFronthead;
head insertFronthead;
head insertFronthead;
head insertFronthead;
head insertFronthead;
head insertFronthead;
head insertFronthead;
head insertFronthead;
head insertFronthead;
insertBackhead;
insertBackhead;
insertBackhead;
insertBackhead;
insertBackhead;
insertBackhead;
insertBackhead;
insertBackhead;
insertBackhead;
insertBackhead;
Print the list
printfInitial List
;
printListhead;
END OF SECTION
Insert the value at index of the linked list using insertMiddle
Print the list
printfList after inserting at index
;
Insert the value at index of the linked list using insertMiddle
Print the list
printfList after inserting at index
;
Delete the node at index using deleteMiddle
Print the list
printfList after deleting index
;
Delete the node holding the value of from the inked list using deleteValue
Print the list
printfList after deleting value
;
Delete the entire list using deleteList
Print the list
printfResult of deleting entire list
;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
