aboutsummaryrefslogtreecommitdiffstats
path: root/OLD/ee1301/wk5/lab4/strap012_lab4_w_2.cpp
diff options
context:
space:
mode:
authorRossTheRoss <mstrapp@protonmail.com>2020-01-30 16:55:04 -0600
committerRossTheRoss <mstrapp@protonmail.com>2020-01-30 16:55:04 -0600
commit175721a63b426355274fa9e8063f762020ab8362 (patch)
treecf2c1b33233d660c9f50de5e659b9343bb264984 /OLD/ee1301/wk5/lab4/strap012_lab4_w_2.cpp
parentMake Python thing in Python (diff)
downloadhomework-175721a63b426355274fa9e8063f762020ab8362.tar
homework-175721a63b426355274fa9e8063f762020ab8362.tar.gz
homework-175721a63b426355274fa9e8063f762020ab8362.tar.bz2
homework-175721a63b426355274fa9e8063f762020ab8362.tar.lz
homework-175721a63b426355274fa9e8063f762020ab8362.tar.xz
homework-175721a63b426355274fa9e8063f762020ab8362.tar.zst
homework-175721a63b426355274fa9e8063f762020ab8362.zip
R E A R R A N G E
Diffstat (limited to 'OLD/ee1301/wk5/lab4/strap012_lab4_w_2.cpp')
-rw-r--r--OLD/ee1301/wk5/lab4/strap012_lab4_w_2.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/OLD/ee1301/wk5/lab4/strap012_lab4_w_2.cpp b/OLD/ee1301/wk5/lab4/strap012_lab4_w_2.cpp
new file mode 100644
index 0000000..5b82cd4
--- /dev/null
+++ b/OLD/ee1301/wk5/lab4/strap012_lab4_w_2.cpp
@@ -0,0 +1,54 @@
+#include <iostream>
+using namespace std;
+
+void bsort(int list[], int length);
+void swap (int &a, int &b);
+void printArray (int list[], int length);
+void makeArray (int list[], int length);
+const int n=50;
+
+int main () {
+int list[n];
+makeArray(list,n);
+bsort(list, n);
+printArray(list, n);
+}
+
+//This function makes the array used for the rest of the program.
+void makeArray(int list[], int length) {
+ int temp=100;
+ for (int i=0; i<n; i++) {
+ list[i]=temp;
+ temp--;
+ }
+}
+
+//This function is the algorithm.
+void bsort(int list[], int length) {
+ for (int i=0; i<n; i++) {
+ for (int j=0; j<n-1; j++) {
+ if (list[j]>list[j+1]) {
+ //This is so the bubble can happen
+ swap(list[j], list[j+1]);
+ }
+ }
+ }
+}
+
+//This function simply swaps two values so the bubbling can commence
+void swap (int &a, int &b) {
+ int temp;
+ temp=a; a=b; b=temp;
+}
+
+//This function prints the array at 5 per line.
+void printArray (int list[], int length) {
+ int k=0;
+ for (int j=0; j<(n/10)*2; j++) {
+ for (int i=0; i<5; i++) {
+ cout << list[k] << " ";
+ k++;
+ }
+ cout << endl;
+ }
+}