FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
C/sorting/comb_sort.c at master · SelfCodeLearning/C · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
SelfCodeLearning
/
C
Public
forked from
TheAlgorithms/C
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
C
/
sorting
/
comb_sort.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (45 loc) · 937 Bytes
Breadcrumbs
C
/
sorting
/
comb_sort.c
Copy path
File metadata and controls
48 lines (45 loc) · 937 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#include
<stdio.h>
#include
<stdlib.h>
#define
SHRINK
1.3 //suggested shrink factor value
void
sort
(
int
*
numbers
,
int
size
)
{
int
gap
=
size
;
while
(
gap
>
1
)
//gap = 1 means that the array is sorted
{
gap
=
gap
/
SHRINK
;
int
i
=
0
;
while
((
i
+
gap
)
<
size
)
{
//similiar to the Shell Sort
if
(
numbers
[
i
]
>
numbers
[
i
+
gap
])
{
int
tmp
=
numbers
[
i
];
numbers
[
i
]
=
numbers
[
i
+
gap
];
numbers
[
i
+
gap
]
=
tmp
;
}
i
++
;
}
}
}
void
display
(
int
*
array
,
int
n
)
{
int
i
;
for
(
i
=
0
;
i
<
n
;
++
i
)
printf
(
"%d "
,
array
[
i
]);
printf
(
"\n"
);
}
int
main
()
{
int
size
=
6
;
int
*
numbers
=
malloc
(
size
*
sizeof
(
int
));
printf
(
"Insert %d unsorted numbers: \n"
,
size
);
int
i
;
for
(
i
=
0
;
i
<
size
;
++
i
)
scanf
(
"%d"
,
&
numbers
[
i
]);
printf
(
"Initial array: "
);
display
(
numbers
,
size
);
sort
(
numbers
,
size
);
printf
(
"Sorted array: "
);
display
(
numbers
,
size
);
free
(
numbers
);
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL