-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
70 lines (60 loc) · 1.11 KB
/
Copy pathmain.c
File metadata and controls
70 lines (60 loc) · 1.11 KB
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
69
70
#include <stdio.h>
#include <stdlib.h>
#define N 10
void InsertSortForArrayModel(int* arr, int length);
void InsertOneNumber(int* arr, int subscript);
void PrintArray(int* arr, int length);
int main()
{
int arr[N];
int i;
printf("Input your %d numbers:\n", N);
for(i = 0; i < N; i++)
{
scanf("%d", &arr[i]);
}
InsertSortForArrayModel(arr, N);
PrintArray(arr, N);
return 0;
}
void InsertSortForArrayModel(int* arr, int length)
{
int i;
for(i = 0; i < length; i++)
{
InsertOneNumber(arr, i);
}
return;
}
void InsertOneNumber(int* arr, int subscript)
{
int i;
int temp = arr[subscript];
for(i = subscript - 1; i >= 0; i--)
{
if(arr[i] > temp)
{
arr[i + 1] = arr[i];
}
else
{
break;
}
}
arr[i + 1] = temp;
return;
}
void PrintArray(int* arr, int length)
{
int i;
int count = 0;
for(i = 0; i < length; i++)
{
if(count != 0 && count%10 == 0)
{
printf("\n");
}
printf("%d ", arr[i]);
}
return;
}