-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathBrute_Force.c
More file actions
43 lines (40 loc) · 802 Bytes
/
Copy pathBrute_Force.c
File metadata and controls
43 lines (40 loc) · 802 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
/* Brute Force Example 11.05.2018
* Halil DURMUÞ ITU BLG221
* Code is taken from the link, for the lecture
* https://www.geeksforgeeks.org/radix-sort/
*/
#include "stdio.h"
int find_minimum(int arr[], int n)
{
int min = arr[0];
int minIndex = 0;
for (int i = 0; i < n; i++)
{
if (arr[i] < min)
{
min = arr[i];
minIndex = i;
}
}
return minIndex;
}
void brute_force_sort(int arr[], int n)
{
int newArray[8];
int minIndex = 0;
for (int i = 0; i < n; i++)
{
newArray[i] = arr[find_minimum(arr, n)];
arr++;
n--;
printf("%d", newArray[i]);
}
}
// Driver program to test above functions
int main()
{
int arr[] = { 170, 45, 75, 90, 802, 24, 2, 66 };
int n = sizeof(arr) / sizeof(arr[0]);
brute_force_sort(arr, n);
return 0;
}