Write a function that takes in a pointer to the head of a linked list, a value to insert into thelist, val, and a location in the list in which to insert it, place, which is guaranteed to be greaterthan 1, and does the insertion. If place number of items aren’t in the list, just insert the item inthe back of the list. You are guaranteed that the linked list into which the inserted item is being

Respuesta :

Answer:

Explanation:

6.....................................

void insertToPlace(struct node * &T,int val,int place)

{

struct node * q=T;

int count =1;

while(T->next!=NULL&&count<place-1)

{

T=T->next;

count++;

}

if(T->next==NULL)

{

struct node * p = (struct node *)new struct node;

p->data=val;

p->next=NULL;

T->next=p;

}

 

else

{

struct node * p = (struct node *)new struct node;

p->data=val;

p->next=T->next;

T->next=p;

}

T=q;

}

ACCESS MORE