-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyarray.c
More file actions
50 lines (39 loc) · 717 Bytes
/
Copy pathmyarray.c
File metadata and controls
50 lines (39 loc) · 717 Bytes
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
#include<stdio.h>
#include "myarray.h"
int sort_array(int *a, int len)
{
for(int i=0; i<len-1; ++i)
{
find_min_and_swap(a+i, len-i);
}
return 0;
}
int print_array(int *a, int len)
{
for(int i=0; i<len; ++i)
{
printf("%d ", a[i]);
}
printf("\n");
return 0;
}
int find_min_and_swap(int *a, int len)
{
int j = 0; //location
int m = a[0]; //min value
for(int i=1; i<len; ++i)
{
if(a[i]<m)
{
m = a[i];
j = i;
}
}
//printf("min value:%d\n", m);
//printf("location:%d\n", j);
//swap the value of a[j] with a[0]
// m = a[j];
a[j] = a[0];
a[0] = m;
return 0;
}