void shaker(char *items, int
count)
|
|||
{
|
|||
08
|
register int
a;
|
|
09
|
int exchange;
|
10
|
char t;
|
|
11
|
|
12
|
do {
|
|
13
|
exchange
= 0;
|
14
|
for(a=count-1;
a > 0; --a) {
|
|
15
|
if(items[a-1]
> items[a]) {
|
16
|
t
= items[a-1];
|
|
17
|
items[a-1]
= items[a];
|
18
|
items[a]
= t;
|
19
|
exchange
= 1;
|
20
|
}
|
|
21
|
}
|
22
|
|
|
23
|
for(a=1;
a < count; ++a) {
|
24
|
if(items[a-1]
> items[a]) {
|
|
25
|
t
= items[a-1];
|
26
|
items[a-1]
= items[a];
|
|
27
|
items[a]
= t;
|
28
|
exchange
= 1;
|
|
29
|
}
|
30
|
}
|
|
31
|
} while(exchange);
/* sort until no exchanges take place */
|
32
|
}
|
|
33
|
|
34
|
int main(void)
|
|
35
|
{
|
36
|
|
|
37
|
char s[255];
|
38
|
|
|
39
|
printf("Enter
a string:");
|
40
|
gets(s);
|
|
41
|
shaker(s,
strlen(s));
|
42
|
printf("The
sorted string is: %s.\n", s);
|
|
43
|
|
44
|
return 0;
|
|
45
|
}
|
No comments:
Post a Comment