У меня есть проект с подписчиками, и у каждого из подписчиков есть несколько контрактов. Проблема в том, что мне приходится сортировать узлы напрямую, когда я их добавляю.Пока что я прилагаю ниже свою программу. Добавление подписчика работает отлично, но когда я пытаюсь добавить другой контракт подписчику, это не работает.Есть предложения?
subscriber_t *addContract(subscriber_t *root, char name[20])
contract_t* newNode = malloc(sizeof(contract_t));
strcpy(newNode->name, name);
contract_t* aux = root->contractInfo;
contract_t** aux2 = &root->contractInfo;//aux 2 is used to retain the position where we want to put our new node
while(aux != NULL && (strcmp(aux->name, newNode->name) < 0)) //we go through the list until we reach the first element bigger than current element
{
aux2 = &aux->next;
aux = aux->next;
}
*aux2 = newNode;//we put on the position we wanted the initial data
newNode->next = aux;//then we move the root on the next position
return root;
https://pastebin.com/R9LEMb57