Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write this program in C language! There are no specific requirements for the mai

ID: 3683232 • Letter: W

Question

Write this program in C language!

There are no specific requirements for the main function, other than it must successfully demonstrate all of the other required functions. You may leave my sample code (output shown below) or modify it as you wish. You will need to successfully implement the following functions: insertFront Inserts a new node to the front of the list Params: head pointer, integer data insertBack Inserts a new node to the back of the Iist Params: head pointer, integer data Print Prints the current linked list Params: head pointer This is the ONLY function that will print anything!! Max Returns the maximum value in the list. (Does not print) Params: head pointer Min Returns the minimum value in the list (Does not print) Params: head pointer loclnlist Returns the location of a number in the list. (Does not print) Locations should start at 0, like an array. If the number is not in the list, return -1 Params: head pointer, integer to search for Sample Output: 3 4 5 6 Max: 6 Min: 0 locInList 5:1 locInList 9: -1

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int data;
struct Node *next;
}node;
void insert(node *pointer, int data)
{
/* Iterate through the list till we encounter the last node.*/
while(pointer->next!=NULL)
{
pointer = pointer -> next;
}
/* Allocate memory for the new node and put data in it.*/
pointer->next = (node *)malloc(sizeof(node));
pointer = pointer->next;
pointer->data = data;
pointer->next = NULL;
}
void print(node *pointer)
{
node *temp;
temp=pointer;
printf("%d ",pointer->data);
while(pointer->next != NULL)
{


pointer = pointer->next;
printf("%d ",pointer->data);
}

printf(" max : %d ",maximum(pointer));
printf(" min : %d ",minimum(temp));


}
int maximum(node *pointer)
{
int max=pointer->data;

while(pointer->next != NULL )
{
if(max <= pointer->data)
max=pointer->data;
pointer=pointer->next;
}
return max;

}
int minimum(node *pointer)
{
int min=pointer->data;

while(pointer->next != NULL)
{
if(min >= pointer->data)
min=pointer->data;
pointer=pointer->next;
}
return min;
}
int main()
{
/* start always points to the first node of the linked list.
temp is used to point to the last node of the linked list.*/
node *start,*temp;
start = (node *)malloc(sizeof(node));
temp = start;
temp -> next = NULL;
/* Here in this code, we take the first node as a dummy node.
The first node does not contain data, but it used because to avoid handling special cases
in insert and delete functions.
*/
printf("1. Insert ");
printf("2. Print ");
printf("3. exit ");
while(1)
{
int query;
printf("Choose Option :");
scanf("%d",&query);
if(query==1)
{
int data;
printf("Enter Data :");
scanf("%d",&data);
insert(start,data);
}

else if(query==2)
{
printf("The list is ");
print(start->next);

printf(" ");
}
else if(query==3)
{
exit(0);
}
else
printf("Enter correct Option :");

}


}