void sort int sel_x ITEM Curr TMP long head- number for for Curr head-

 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
void sort(int sel_x)
{
ITEM *Curr, *P, *N, *TMP;
long n=head->number, i, k;
for(i=0; i<=n; i++)
{
for(Curr=head->first; Curr->next!=NULL;)
{
TMP=Curr->next;
k=0;
switch(sel_x)
{
case 1:
if(Curr->data->id>TMP->data->id) k=1;
break;
case 2:
if(strcmp(Curr->data->surname, TMP->data->surname)>0) k=1;
break;
case 3:
if(strcmp(Curr->data->drug_form, TMP->data->drug_form)>0) k=1;
break;
case 4:
if(Curr->data->recipe>TMP->data->recipe) k=1;
break;
case 5:
if(Curr->data->cost>TMP->data->cost) k=1;
break;
case 6:
if(Curr->data->exemption>TMP->data->exemption) k=1;
break;
case 7:
if(Curr->data->paid>TMP->data->paid) k=1;
break;
case 8:
if(Curr->data->id>TMP->data->id) k=1;
break;
default:
break;
}
if(k==1)
{
if(Curr->prev==NULL)
head->first=TMP;
if(TMP->next == NULL)
head->last=Curr;
P=Curr->prev;
N=TMP->next;
if(P!=NULL)
P->next=TMP;
if(N != NULL)
N->prev=Curr;
Curr->next=N;
Curr->prev=TMP;
TMP->next=Curr;
TMP->prev=P;
}
else
{
Curr=Curr->next;
}
}
}
}