- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
typedef struct
{
uint8_t arr[10];
uint8_t pos;
uint8_t is_swap;
} arr10;
arr10 bubble_sort_recursion(arr10 a);
void bubble_sort (uint8_t arr[static 10]);
void bubble_sort (uint8_t arr[static 10])
{
arr10 a;
memcpy(a.arr, arr, sizeof(a.arr));
a.pos = 0;
a.is_swap = 0;
a = bubble_sort_recursion(a);
memcpy(arr, a.arr, sizeof(a.arr));
}
arr10 bubble_sort_recursion(arr10 a)
{
if (a.pos != 9)
{
if (a.arr[a.pos] > a.arr[a.pos + 1])
{
uint8_t tmp = a.arr[a.pos + 1];
a.arr[a.pos + 1] = a.arr[a.pos];
a.arr[a.pos] = tmp;
a.is_swap = 1;
}
a.pos++;
return bubble_sort_recursion(a);
}
else
{
if (a.is_swap == 0)
{
return a;
}
else
{
a.pos = 0;
a.is_swap = 0;
return bubble_sort_recursion(a);
}
}
}
int main(void)
{
uint8_t arr[10] = {244, 90, 254, 109, 33, 85, 69, 81, 126, 71};
bubble_sort(arr);
printf("%" PRIu8 ", %" PRIu8 ", %" PRIu8 ", %" PRIu8 ", %" PRIu8 ", %" PRIu8 ", %" PRIu8 ", %" PRIu8 ", %" PRIu8 ", %" PRIu8,
arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7], arr[8], arr[9]);
return 0;
}
j123123 29.11.2018 19:29 # +1
j123123 10.02.2019 17:21 # +1
O4epegHou_nemyx 10.02.2019 17:32 # 0
j123123 10.02.2019 17:37 # 0
O4epegHou_nemyx 10.02.2019 17:39 # 0
cmepmop 10.02.2019 20:36 # 0
O4epegHou_nemyx 10.02.2019 21:02 # 0