I am trying to make a function that sorts the linked list,which sorts the list by names.
struct student
{
char name[50];
int roll_no;
struct student *ptr_next;
}*ptr_this,*ptr_first;/*ptr first points to first pointer */
void SortRecord(void)
{
struct student *out,*in,*temp;
for(out=ptr_first;out!=(struct student*)NULL;out=out->ptr_next)
{
for(in=out->ptr_next;out->ptr_next!=(struct student*)NULL;in=in->ptr_next)
{
if(strcmpi(out->name,in->name)<0)
temp->ptr_next=in->ptr_next;
in->ptr_next=out->ptr_next;
out->ptr_next=temp->ptr_next;/*The program stops at this instant and does not proceed after this line*/
}
}
printf("Records have been successfully sorted.");
I am stuck with 2 questions: EDIT: I understood that we only need to swap the pointers not the contents but my code still hangs at the swapping at the place mentioned above.