1.Write a function last that expects a pointer to the first node in a linked list and returns a pointer to the last node in the linked list or NULL if the list is empty.
2.Write a function append that expects two pointers to the first nodes in two linked lists and returns a pointer to a linked list consisting of the first liked list followed by the second.
3.Write a function reverse that expects a pointer to the first node in a linked list and returns a pointer to a linked list that is the reverse of the original linked list.Do not allocate any new nodes;change pointers.
4.In the program below change the the last node in the linked list points back to the first.You now have a circular linked list.Write a function that prints each node in a circular linked list exactly once,starting at any node in the list.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct elephant
{
chat name[10];
struct elephant* next;
}
ELEPHANT;
void print_elephants(const ELEPHANT* ptr);
main()
{
ELEPHANT elephant1,elephant2,elephatn3,*start;
strcpy(elephant1.name,”Edna”);
strcpy(elephant2.name,”Elmer”);
strcpy(elephant3.name,”Eloise”);
elephant1.next=&elephant2;
elephant2.next=&elephant3;
elephant3.next=NULL;
start =&elephant1;
print_elephants(start);
return EXIT_SUCCESS;
}
void print_elephants(const ELEPHANT* ptr)
{
int count =1;
printf(“nnn”);
while(ptr!= NULL)
{
printf(“nElephant number %d is %s.”,count++,ptr-> name);
ptr=ptr->next;
}
}
5.Illustrate how delete_nth_node works for linked list shown below
#include <stdlib.h>
#include “structure.h”
NODE* find_nth_node(NODE* ptr,int n);
NODE* delete_nth_node(NODE* ptr,int n,int* success_flag)
{
NODE *pred,*old;
if(n==1)
{
if(ptr==NULL)
{
*success_flag=0;
return ptr;
}
old=ptr;
ptr=ptr->next;
}
else
{
pred=find_nth_node(ptr,n-1);
if(pred==NULL || ored->next ==NULL)
{
*success_flag=0;
return ptr;
}
old=pred->next;
pred->next = old ->next;
}
free(old);
*success_flag=1;
return ptr;
}