помогите с сортировкой на Си
Вот то что я сделал, но не работает. Посмотрите пожалуйста:
#include
#include
#include
typedef struct Node{
int number,summa;
char data[11],fio[21];
struct Node *next, *prev;
}NODE;
typedef NODE *PNODE;
void Add_list(PNODE *h, PNODE *t);
void Print(PNODE h);
void sort(PNODE head);
int main()
{
PNODE head = NULL;
PNODE tail = NULL;
Add_list(&head, &tail);
Print(head);
sort(&head);
system ("PAUSE");
return 0;
};
void Add_list(PNODE *h, PNODE *t){
int i = 1;
do{
PNODE NewNode;
NewNode =(struct Node*) malloc(sizeof(NODE));
printf (" New a list\n\n");
printf ("\nNew FIO: ");
gets (NewNode->fio);
if(NewNode->fio[0] == '\0')break;
printf ("New number nakladnoi: ");
scanf ("%d", &NewNode->number);
printf ("New datu: ");
scanf ("%s",NewNode->data);
printf ("New summu: ");
scanf ("%i", &NewNode->summa);
getchar();
NewNode->next = NULL;
NewNode->prev = NULL;
if ((*h) ==NULL){
*t =NewNode;
*h = NewNode;
}
else {
(*t)->next = NewNode;
NewNode->prev = *t;
*t = NewNode;
}
}while(i == 1);
}
void Print(PNODE h){
int a, b;
PNODE CurNode = h;
printf (" Print a list\n");
printf ("----------------------------------------------------------------------------\n");
printf ("| Number | Data | Summa | FIO |\n");
printf ("----------------------------------------------------------------------------\n");
while (CurNode !=NULL){
printf ("|%8i",CurNode->number);
printf ("|s|",CurNode->data);
printf ("i|",CurNode->summa);
printf ("8s|\n",CurNode->fio);
CurNode = CurNode->next;
}
printf ("----------------------------------------------------------------------------");
printf ("\n1. New a list.");
printf ("\n2. Print a list.");
printf ("\n3. Sortirowka.");
printf ("\n4. Exit.");
for(b=0; b!=1;){
scanf ("%d",&a); {
switch(a){
//case 1 : Add_list();
//case 2 : Print();
case 3 : sort();
case 4 : exit(0);
}
}
}
}
void sort(PNODE *head){
PNODE *tmp;
PNODE *a;
int t=0;
bool flag=1;
while(flag==1){
tmp=start;
a=tmp->next;
flag=0;
while(a){
if((tmp->number)>(a->number))
{
t=tmp->number;
tmp->number=a->number;
a->number=t;
flag=1;
}
tmp=tmp->next;
a=a->next;
}
}
Print(head);
}
Вот тыложил [ссылка заблокирована по решению администрации проекта]. com/FnY3SPsV