This came to my mind but I can't work it out.
Code:
struct student
{
char name[20];
int year;
struct student *next;
};
struct student *selection(struct student *head,int year)
{
struct student *temp;
struct student *head1=NULL;
temp = (struct student *)malloc(sizeof(*temp));
temp = head;
while (temp != NULL)
{
if (temp->year == year)
{
temp->next=head1;
head1=temp;
temp=temp->next;
}
}
temp=head1;
if (head1 == NULL)
{
printf("List is empty");
return;
}
else
{
while (temp != NULL)
{
printf("\n");
printf("%s %d",temp->name,temp->year);
printf("\n");
temp=temp->next;
}
}
return;
}