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

Do the following function implementation : void. insert_link. ( int value ); //

ID: 3544323 • Letter: D

Question

Do the following function implementation :

void. insert_link. ( int value ); // This function should insert a Link with the input value at the // front of the list. In other words, if the list has the values: // 34 rightarrow 11 rightarrow 100 rightarrow 94 // and insert_link (28) is called, the list would look like: // 28 rightarrow 34 rightarrow 11 rightarrow 100 rightarrow 94 // HARNING: Be careful to handle the situation where there is // nothing in the list, i.e. firstLink is NULL void. remove_link (int value); // This function should remove the first occurrence of a Link with // the input value, even if there are multiple Links with tha // value. If the list has the values: // 34 rightarrow 11 rightarrow 100 rightarrow 94 rightarrow 100 // and remove_link (100) is called, the list would look like: // 34 rightarrow 11 rightarrow 94 rightarrow 100 // WARNING: Be careful to handle the situation where the input // value is in the first Link (i.e. firstLinkrightarrowdata = value )]

Explanation / Answer

void insert_link(int value)

{

struct node *temp;

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

temp->data=value;

if (firstLink= NULL) /*if there is no node firstLink == NULL*/

{

  firstLink=temp;

  firstLink->next=NULL;

}

else

{

temp->next=firstLink;

  firstLink=temp;

}

}




void remove_link(int value)

{

struct node *temp, *prev;

temp=firstLink;

while(temp!=NULL)

{

if(temp->data==value)

{

if(temp==firstLink) /*it is checking whether the first node has data or not.*/

{

  firstLink=temp->next;

free(temp);

return 1;

}

else

{

prev->next=temp->next;

free(temp);

return 1;

}

}

else

{

prev=temp;

temp= temp->next;

}

}

return 0;

}

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