/
bubblesort.c
58 lines (41 loc) · 1.07 KB
/
bubblesort.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
57
#include <stdio.h>
#include "generateSine.c"
#define SCALING_FACTOR 200
int *bubbleSort(int list[], int length, float lengthOfBeat)
{
int i, j, temp;
int eachNote = 0;
int *noteList;
noteList = (int*) malloc(sizeof(int));
while(!eachNote) {
for (j = 0; j < length - 1; j++) {
for (i = 0; i < length - j - 1; i++) {
if (list[i] > list[i + 1]) {
temp = list[i];
list[i] = list[i + 1];
list[i + 1] = temp;
noteList = realloc(noteList, (eachNote + 1) * sizeof(int));
noteList[eachNote] = list[i] * SCALING_FACTOR;
noteList[eachNote + 1] = list[i + 1] * SCALING_FACTOR;
eachNote = eachNote + 2;
playNote(list[i] * SCALING_FACTOR, lengthOfBeat);
playNote(list[i + 1] * SCALING_FACTOR, lengthOfBeat);
}
}
}
break;
}
int note;
for (note = 0; note < eachNote; note++) {
printf("%d\n", noteList[note]);
}
dumpToFile(noteList, eachNote * sizeof(int), lengthOfBeat, "sounds/bubbleSort.wav");
int *listptr;
listptr = &list[0];
return listptr;
}
int main()
{
populateArray(bubbleSort);
return 0;
}