struct ticket Данные выдаче или возврате авиабилета линейный двунаправ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
struct ticket//Данные о выдаче или возврате авиабилета (линейный двунаправленный список)
{
char ticket_number[10];
char passport[12];
char flight_number[8];
ticket *prev;
ticket *next;
} *head;//начало списка
void sort()
{
ticket *cur;
ticket *cur2;
ticket *tmp=new ticket;
ticket *max=new ticket;
cur=head;
while (cur->next) cur=cur->next;//добежали до последнего элемента в списке
while (cur!=head)
{
strcpy(max->flight_number, head->flight_number);
strcpy(max->passport, head->passport);
strcpy(max->ticket_number, head->ticket_number);
cur2=head->next;
while (cur2)
{
if (strcmp(cur2->ticket_number, max->ticket_number)>0)
{
strcpy(max->flight_number, cur2->flight_number);
strcpy(max->passport, cur2->passport);
strcpy(max->ticket_number, cur2->ticket_number);
}
strcpy(tmp->flight_number, cur->flight_number);
strcpy(tmp->passport, cur->passport);
strcpy(tmp->ticket_number, cur->ticket_number);
strcpy(cur->flight_number, max->flight_number);
strcpy(cur->passport, max->passport);
strcpy(cur->ticket_number, max->ticket_number);
strcpy(max->flight_number, tmp->flight_number);
strcpy(max->passport, tmp->passport);
strcpy(max->ticket_number, tmp->ticket_number);
cur2=cur2->next;
}
cur=cur->prev;
}
}