CSE 100 Lecture Notes - Lecture 42: Bubble Sort
![](https://new-preview-html.oneclass.com/rakV67y5LKMpNOwpMBl2Nw8XEJWevPqo/bg1.png)
Lecture 41
● Start preparing for Exam 4
○ Will act as final (no cumulative final for class)
● Mostly Chapter 9
● Practice Labs and assignments for sample code
● Example of sorting code (going over it in class)
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> intVec;
//Store 5 inputs to intVec
for(int i = 0; i< 5; i++)
{
cout<<"Please enter the value of #"<<i+1<<": ";
int input;
cin>>input;
intVec.push_back(input);
}
cout<<endl;
//Using bubble sort algorithm to sort the vector
boolean flag = false;
do{
flag = false;
for(int j=0; j<intVec.size()-1; j++)
{
if(intVec[j]>intVec[j+1])
{
int temp = intVec[j];
intVec[j] = intVec[j+1];
intVec[j+1] = temp;
flag = true;
}
}
}while(flag);
//Display the sorted vector