Advertisement
alaminrifat

Bubble Sort in C++

Oct 17th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4.     int n = 8;
  5.     int arr[n]={4,7,3,1,5,8,2,6},t=0,temp,k=n;
  6.     while(k!=0){
  7.         for(int j=0;j<=k-1;j++){
  8.             if(arr[j]>arr[j+1]){
  9.                 temp = arr[j];
  10.                 arr[j] = arr[j+1];
  11.                 arr[j+1] = temp;
  12.             }
  13.         }
  14.         k--;
  15.     }
  16.  
  17.     for(int i = 0 ; i < n ; i++){
  18.         cout<<arr[i]<<" ";
  19.     }
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement