BDSX1U The Asker · Computer Science

Consider the following linked list node structure:

struct node{

int data;

struct node *next;

};

Implement the following basic functions of the linear linked list structure:

1. Check empty list

{

return 1; //TRUE

else

return 0; //FALSE

}

1. Create a node

struct node * newnode(int d)

{

struct node *temp;

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

temp->data =d;

temp->next=NULL;

return temp;

}

1. Insert a node into front/back/middle of LL

struct node * insertFront(struct node *header, int d)

{

struct node *temp;

temp=newnode(d);

}

struct node * insertBack(struct node *header, int d)

{

temp=newnode(d);

{

}

}

void insertAfter(struct node *afterNode, int d)

{

struct node *temp;

temp=newnode(d);

temp->next=afterNode->next;

afterNode->next=temp;

}

1. Delete a node from front/back/middle of LL

struct node * deleteFront(struct node *header)

{

struct node *temp;

free(temp);

}

struct node * deleteBack(struct node *header)

{

free(temp);

}

void deleteAfter(struct node *afterNode)

{

struct node *temp;

if(afterNode->next==NULL || afterNode==NULL)

return;

temp =afterNode->next;

afterNode->next=temp->next;

free(temp); }

Task 1: Write down a complete C/C++ program to test your linear linked list implementation. Additionally, write another function which will be used to list the linked list content. Complete your implementation using the following code:

Task 2: Write a function that inserts a node to nth place of a Linear Linked List. Consider the following prototype:

struct node * insertn (struct node * p, int n);

Task 3: Write a function that deletes all the nodes in the given linked list.

void deletelist (struct node *);

Task 4: Write a function that copies a linked list. Source and destination lists are the input parameters to the function.

void copylist (struct node *,struct node * );

More