Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include "timer.h"
- using namespace std;
- //function declarations
- void BubbleSort(vector<int>, int n);
- void SelectionSort(int n);
- int MinElement(int n);
- //main
- int main()
- {
- int choice=0;
- int length=0;
- cout<<"Choose algorithm: "<<endl;
- cout<<"1. MinElement"<<endl;
- cout<<"2. Bubble Sort"<<endl;
- cout<<"3. Selection Sort"<<endl;
- cout<<"Choice: ";
- cin>>choice;
- cout<<"How big is the array? ";
- cin>>length;
- vector <int> sortThis[length];
- for(int i=0;i<length;i++)
- {
- sortThis[i]=rand()%100;
- }
- switch(choice)
- {
- case 1:
- MinElement(length);
- break;
- case 2:
- BubbleSort(sortThis, length);
- break;
- case 3:
- SelectionSort(length);
- break;
- default:
- cout<<"Invalid choice. End program.";
- break;
- }
- return 0;
- }
- //function definitions
- void BubbleSort(vector <int> sortThis, int n)
- {
- int temp;
- for(int i=0;i<n-1;i++)
- {
- if(sortThis[i]>sortThis[i+1])
- {
- temp=sortThis[i];
- sortThis[i]=sortThis[i+1];
- sortThis[i+1]=temp;
- }
- }
- }
- void SelectionSort(vector <int> sortThis, int n)
- {
- int temp;
- for(int i=0;i<n-1;i++)
- {
- if(sortThis[i]<sortThis[i+1])
- {
- temp=sortThis[i];
- sortThis[i]=sortThis[i+1];
- sortThis[i+1]=temp;
- }
- }
- }
- int MinElement(vector <int> sortThis, int n)
- {
- int min=sortThis[0];
- for(int i=1;i<n;i++)
- {
- if(sortThis[i]<min)
- min=sortThis[i];
- }
- return min;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement