Question: 1. Write a function insert PosN() for a singly-linked list that has the following declaration and precondition: int insert PosN (struct node **pHead, int n,

 1. Write a function insert PosN() for a singly-linked list that

1. Write a function insert PosN() for a singly-linked list that has the following declaration and precondition: int insert PosN (struct node **pHead, int n, char *newData); Precondition: n > 0. The function should allocate space for a node, initialize it with a copy of the data found in parameter newData, and attempt to insert it at position n in the list. The first node starts at position 1. If the node is successfully inserted into the list at position n, then the function must return 1. If memory could not be allocated for the node, then the function must return 0. If there are fewer nodes in the list than specified by n-1, then the function must insert the node at the end of the list and return -1. A node, struct node, is defined as follows: struct node { char data[100]; struct node *pNext; }

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 Databases Questions!