Помогите решить в СИ
Создать односвязный список: Структура содержит фамилию, год рождения. Добавлять новые записи так, чтобы список был упорядочен по возрасту Просто выводит список, никак его не сортируя + требуется добавить новые данные, которые надо отсортировать.
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <stdlib.h>
struct spis
{
char data[20];
int *years[12];
struct spis *next;
};
struct spis * create(void);
void list(spis *head);
struct spis *head;
int main()
{
system("chcp 1251");
years = (int *)malloc(12 * sizeof(int));
int tmp;
bool noSwap;
for (int i = N - 1; i >= 0; i--)
{
noSwap = 1;
for (int j = 0; j < i; j++)
{
if (years[j] > years[j + 1])
{
tmp = years[j];
years[j] =years[j + 1];
years[j + 1] = tmp;
noSwap = 0;
}
}
if (noSwap == 1)
break;
}
printf("Sorted array:\n");
for (int i = 0; i < N; i++)
printf("%d ", years[i]);
printf("\n");
free(years);
return 0;
head = create();
list(head);
free(head);
return 0;
}
struct spis * create(void)
{
spis *p, *pred; char c;
head = pred = p = (spis *)malloc(sizeof(spis));
printf(" fam: ");
scanf("%s", p->data, _countof(p->data));
printf(" year: ");
scanf("%s", p->years, _countof(p->years));
do {
p = (spis *)malloc(sizeof(spis));
printf("\n fam: ");
scanf("%s", p->data, _countof(p->data));
printf("\n year: ");
scanf("%s", p->years, _countof(p->years));
pred->next = p;
pred = p;
printf(" Закончить? y/n ");
c = _getch();
}
while (c != 'y');
p->next = NULL;
return head;
}
void list(spis *head)
{
spis *p;
p = head;
printf("\n List\n");
while (p != NULL){
printf("\n fio: %s", p->data);
printf("\n year: %s", p->years);
p = p->next;
}
_getch();
}