-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.c
56 lines (48 loc) · 1.2 KB
/
shell.c
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
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int *elements_array = NULL;
void random_range(int n, int max) {
int r, i;
int N = 1,
M = max;
srand (time(NULL));
for(i=0; i < n ; i++){
r = M + rand() / (RAND_MAX / (N - M + 1) + 1);
elements_array[i] = r;
}
printf("Elementy zbioru: ");
for(i=0; i < n ; i++){
printf("%d,", elements_array[i]);
}
}
int main(){
int i, j, incr, tmp, n, max;
printf("Podaj liczbę elementów: ");
scanf("%d",&n);
printf("Podaj max. wartość zbioru: ");
scanf("%d",&max );
elements_array = malloc(sizeof(int)*n);
random_range(n, max);
for(incr = n/2; incr > 0; incr /= 2)
{
for(i = incr; i < n; i++)
{
tmp = elements_array[i];
for(j = i; j >= incr; j -= incr)
{
if(tmp < elements_array[j-incr])
elements_array[j] = elements_array[j-incr];
else
break;
}
elements_array[j] = tmp;
}
}
printf("\nElementy posortowane: ");
for(i = 0; i < n; i++)
printf("%d ",elements_array[i]);
printf("\n");
free(elements_array);
return 0;
}