[QUOTE=shardin;673572]
Code:
struct student{
char ime[20];
int mbr;
struct student *next;
};
Ok i understand it..as earlier u have considered it a sorted list. Please see my function to insert in sorted list
Code:
struct student *dodaj_di_triba(struct student *head, int mb,char *ime){
struct student *temp;
struct student *dodaj;
struct student *successor;
dodaj = (struct student *)malloc(sizeof(struct student));
dodaj->mbr=mb;
strcpy(dodaj->ime,ime);
temp = head;
if((head->mbr)<=(dodaj->mbr))
{
dodaj->next=head;
/* we are returning the head pointer to traverse the whole list*/
return dodaj;
}
else
{
while((temp->mbr)<(dodaj->mbr))
{
successor = temp->next;
if(successor == NULL)
{
temp->next = dodaj;
dodaj->next = NULL;
/* returning the head pointer */
return head;
}
if((successor->mbr)>=(dodaj->mbr))
{
temp->next=dodaj;
dodaj->next=successor;
return head;
}
temp= temp->next;
}
}