Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Jeffrey Liv 892041518
- //CPSC 131
- //Project 1 Part 2
- //Use sorting algorithms to sort 3 different arrays
- #include <iostream>
- #include <string>
- using namespace std;
- void SortArray(int a[], int n){
- int swap;
- int min;
- for(int i = 0; i < n - 1; i++)
- {
- min = i;
- for(int j = i + 1; j < n; j++)
- {
- if(a[min] > a[j])
- min = j;
- }
- if(min != i){
- swap = a[min];
- a[min] = a[i];
- a[i] = swap;
- }
- }
- }
- void DisplayArray(int a[], int n){
- for(int i = 0; i < n; i++)
- {
- cout << a[i] << " ";
- }
- cout << endl;
- }
- int main(){
- int a[6] = {44, 55, 22, 88, 33, 11};
- string month[12] = {"Jan", "Feb", "Mar", "Apr", "May",
- "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
- char vowels[5] = {'E', 'U', 'A', 'I', 'O'};
- cout << "Original Array a: ";
- DisplayArray(a, 6);
- SortArray(a, 6);
- cout << "Sorted Array a: ";
- DisplayArray(a, 6);
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement