formatting source-code for d7af6fdc8c

This commit is contained in:
github-actions
2020-05-29 23:26:30 +00:00
parent edb3d51ec2
commit 7ad1f171c1
176 changed files with 5342 additions and 4288 deletions

View File

@@ -5,11 +5,13 @@
#define BEAD(i, j) beads[i * max + j]
// function to perform the above algorithm
void beadSort(int *a, int len) {
void beadSort(int *a, int len)
{
// Find the maximum element
int max = a[0];
for (int i = 1; i < len; i++)
if (a[i] > max) max = a[i];
if (a[i] > max)
max = a[i];
// allocating memory
unsigned char *beads = new unsigned char[max * len];
@@ -19,10 +21,12 @@ void beadSort(int *a, int len) {
for (int i = 0; i < len; i++)
for (int j = 0; j < a[i]; j++) BEAD(i, j) = 1;
for (int j = 0; j < max; j++) {
for (int j = 0; j < max; j++)
{
// count how many beads are on each post
int sum = 0;
for (int i = 0; i < len; i++) {
for (int i = 0; i < len; i++)
{
sum += BEAD(i, j);
BEAD(i, j) = 0;
}
@@ -32,9 +36,11 @@ void beadSort(int *a, int len) {
}
// Put sorted values in array using beads
for (int i = 0; i < len; i++) {
for (int i = 0; i < len; i++)
{
int j;
for (j = 0; j < max && BEAD(i, j); j++) {
for (j = 0; j < max && BEAD(i, j); j++)
{
}
a[i] = j;
@@ -43,7 +49,8 @@ void beadSort(int *a, int len) {
}
// driver function to test the algorithm
int main() {
int main()
{
int a[] = {5, 3, 1, 7, 4, 1, 1, 20};
int len = sizeof(a) / sizeof(a[0]);