-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbubbleSort.cpp
28 lines (28 loc) · 866 Bytes
/
bubbleSort.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<iostream>
#include<vector>
using namespace std;
class bubbleSortClass{
public:
static vector<int> bubbleSort(vector<int> inputVector){
for(int i=0;i<(inputVector.size())-1;i++){
for(int j=i+1;j<(inputVector.size())-i-1;j++){
if(inputVector[j]>inputVector[j+1]){
int temp = inputVector[j];
inputVector[j]=inputVector[j+1];
inputVector[j+1] = temp;
}
}
}
return inputVector;
}
static void printVector(vector<int> inputVector){
for(int i=0;i<inputVector.size();i++){
cout<<inputVector[i]<<" ";
}
}
};
int main(){
vector<int> firstArray = {1,3,2,10,8,9,4,6,5,7};
firstArray = bubbleSortClass::bubbleSort(firstArray);
bubbleSortClass::printVector(firstArray);
}