From 7a73162607544204032aa66cce755daf21edebda Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Tue, 24 May 2022 11:18:46 -0500 Subject: Graduate Signed-off-by: Matt Strapp --- ee1301/wk5/lab4/strap012_lab4_w_2.cpp | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 ee1301/wk5/lab4/strap012_lab4_w_2.cpp (limited to 'ee1301/wk5/lab4/strap012_lab4_w_2.cpp') diff --git a/ee1301/wk5/lab4/strap012_lab4_w_2.cpp b/ee1301/wk5/lab4/strap012_lab4_w_2.cpp new file mode 100644 index 0000000..5b82cd4 --- /dev/null +++ b/ee1301/wk5/lab4/strap012_lab4_w_2.cpp @@ -0,0 +1,54 @@ +#include +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; ilist[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; + } +} -- cgit v1.2.3