From cf3a29feb5887344b6633ead1b4b6d5657a15a4b Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sun, 15 Jun 2014 03:24:33 +0200 Subject: old stuff: algorithms --- algorithms/bubble_sort.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 algorithms/bubble_sort.cc (limited to 'algorithms/bubble_sort.cc') diff --git a/algorithms/bubble_sort.cc b/algorithms/bubble_sort.cc new file mode 100644 index 0000000..ccf7b35 --- /dev/null +++ b/algorithms/bubble_sort.cc @@ -0,0 +1,45 @@ +#include + +#define N 4 +#define TRUE 1 +#define FALSE 0 + + +void +bubbleSort(int *A, int n) +{ + int i, t, change, pos, newpos; + pos = n - 1; + newpos = 0; + do { + change = FALSE; + for (i=0; iA[i+1]) { + t = A[i+1]; + A[i+1] = A[i]; + A[i] = t; + newpos = i - 1; + change = TRUE; + } + } + pos = newpos; + } while (change); +} + + +int main (int argc, char * const argv[]) { + int A[N] = {3,1,1,2}; + + for(unsigned int i=0; i