Witam właśnie robię swój pierwszy projekt na studia. Stworzyłem funkcje dodające element do listy ale nie potrafię wykonać do nich sortowan ponieważ w jednej funki potrzebuje sortowania przez ID, a w drugiej przez Nazwisko a potem imie poniżej wstawiam kod:
Prosiłbym o jakieś nakierowanie jak to zrobić
node1* stworz_element1()
{
node1 *element;
char bufor[999 + 1];
int id;
char *nazwa; char *opis; char *start; char *stan; char *koniec;
system("cls");
printf("Id: ");
scanf("%d", &id);
printf("Nazwa: ");
gets(bufor);
nazwa = (char*)malloc(sizeof(char)* (strlen(bufor) + 1));
strcpy(nazwa, bufor);
printf("Opis: ");
gets(bufor);
opis = (char*)malloc(sizeof(char)* (strlen(bufor) + 1));
strcpy(opis, bufor);
printf("Start: ");
gets(bufor);
start = (char*)malloc(sizeof(char)* (strlen(bufor) + 1));
strcpy(start, bufor);
printf("Stan: ");
gets(bufor);
stan = (char*)malloc(sizeof(char)* (strlen(bufor) + 1));
strcpy(stan, bufor);
printf("Koniec: ");
gets(bufor);
koniec = (char*)malloc(sizeof(char)* (strlen(bufor) + 1));
strcpy(koniec, bufor);
element = (node1*)malloc(sizeof(node1));
element->next = NULL;
element->data1.id = id;
element->data1.nazwa = nazwa;
element->data1.opis = opis;
element->data1.start = start;
element->data1.stan = stan;
element->data1.koniec = koniec;
return element;
}
node2* stworz_element2()
{
node2 *element;
char bufor[999 + 1];
char *imie; char *nazwisko; char *adres; char *pesel; char *numer;
system("cls");
printf("Imie: ");
gets(bufor);
imie = (char*)malloc(sizeof(char)* (strlen(bufor) + 1));
strcpy(imie, bufor);
printf("Nazwisko: ");
gets(bufor);
nazwisko = (char*)malloc(sizeof(char)* (strlen(bufor) + 1));
strcpy(nazwisko, bufor);
printf("Adres: ");
gets(bufor);
adres = (char*)malloc(sizeof(char)* (strlen(bufor) + 1));
strcpy(adres, bufor);
printf("Pesel: ");
gets(bufor);
pesel = (char*)malloc(sizeof(char)* (strlen(bufor) + 1));
strcpy(pesel, bufor);
printf("Numer telefnu: ");
gets(bufor);
numer = (char*)malloc(sizeof(char)* (strlen(bufor) + 1));
strcpy(numer, bufor);
element = (node2*)malloc(sizeof(node2));
element->next = NULL;
element->data2.imie = imie;
element->data2.nazwisko = nazwisko;
element->data2.adres = adres;
element->data2.pesel = pesel;
element->data2.numer = numer;
return element;
}