I have a list whose structure is the following:
Code:
typedef struct dats_s
{
char email[MAX_STR];
struct data_s *next;
} data;
and I need to order the elements of the list alpabetically I've produced the following code but it seem not to work... the idea is to use two pointer and two while cycles so that I compare the first element of the list pointed by the first pointer while I scroll from the second to the last element of the list in serch of a smaller element; when I find it I simply exchange the two strings using a temporary string; when the second pointer reaches the end of the list I repeat this process starting from the second element and so on...
this is the code involved in the sorting process:
Code:
p_corr1=p_head;
p_corr2=(*p_corr1).next;
while(p_corr1!=NULL)
{
while(p_corr2!=NULL)
{
if(strcmp((*p_corr1).email,(*p_corr2).email)>0)
{
strcpy(temp_email,(*p_corr1).email);
strcpy((*p_corr1).email,(*p_corr2).email);
strcpy((*p_corr2).email,temp_email);
}
p_corr2=(*p_corr2).next;
}
p_corr1=(*p_corr1).next;
}
any suggestion is welcome!!
Thank