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

This is a four parter question about the following stuct in C language. Thank yo

ID: 3597143 • Letter: T

Question

This is a four parter question about the following stuct in C language. Thank you for your time.

A linked list of integers is built using the following struct:
struct node {
  int data;
  struct node *next;
};

1. Write a function named createNode that has one integer argument. The function (a) allocates a new struct node, using malloc, (b) sets the data field of the new node to the value passed in by the function, (c) sets the next field of the new node to NULL (zero), and (d) returns the address of the new node.

2. We have two variables, named n1 and n2, which are both of type struct node *. Write a statement that makes the next field of the node pointed to by n1 equal n2. (In other words, the first node will point to the second node, using its next field.) Do not change the values of the variables.

3. Define a function named max that finds and returns the largest integer in a list. The function takes one argument, a pointer to the head of the list. If the list is empty, the function returns zero.

4. Define a function named pop that removes the first node from the list. The function takes one argument: a pointer to the head of the list. The function returns a pointer to the new head of the list.
DO NOT use free() to deallocate the removed node. (It will break the test program, if you do.) If the original list is empty, then the function must return NULL.

Explanation / Answer

Please find my answer:

1)

struct node* createNode(int x) {

struct node *newNode = (struct node*)malloc(sizeof(struct node));

newNode->data = x;

newNode->next = NULL;

return newNode;

}

2)

n1->next = n2;

3)

int max(struct node *head) {

if(head == NULL)

return 0;

int large = head->data;

head = head->next;

while(head != NULL) {

if(large < head->data)

large = head->data;

head = head->next;

}

return large;

}

4)

int max(struct node *head) {

if(head != NULL)

head = head->next;

return head;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote