void insert(SLL *list, Employee e){
NODE *temp, *current, *temp2;
temp = (NODE *)malloc(sizeof(NODE));
assert(temp != NULL);
temp -> anEmployee = (Employee *)malloc(sizeof(Employee));
assert(temp -> anEmployee != NULL);
strcpy(temp -> anEmployee -> name, e.name);
temp -> anEmployee -> ID = e.ID;
strcpy(temp -> anEmployee -> address, e.address);
strcpy(temp -> anEmployee -> city, e.city);
temp -> anEmployee -> age = e.age;
temp -> next = NULL;
if (list -> head == NULL) { /* list is empty */
list -> head = list -> tail = temp;
return;
}
else { // list is not empty
current = list-> head;
while(current -> next != NULL && strcmp(temp-> anEmployee -> name, current-> anEmployee -> name)>0){
current = current -> next;
}
if(current -> next == NULL){
list -> tail -> next = temp;
list -> tail = temp;
}
else{
temp -> next = current -> next;
current -> next = temp;
}
}
}
Он правильно вставляет сотрудников и размещает их в отсортированном порядке, как будто это единственная проблема, с которой я сталкиваюсь, - это то, что первый сотрудник в списке не сортируется.