Advertisement
Guest User

Bubble Sort CPP

a guest
Mar 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #define SIZE 10
  3. using namespace std;
  4. int main(){
  5. int arr[10];
  6.  
  7. for(int inputCnt = 0; inputCnt < SIZE; inputCnt++){
  8. cout << "[" << inputCnt << "]: ";
  9. cin >> arr[inputCnt];
  10. }
  11. for(int a = 0; a < SIZE; a++){
  12. for(int b = 0; b < SIZE-a; b++){
  13. if (arr[b] > arr[b+1]){
  14. int temp = arr[b];
  15. arr[b] = arr[b+1];
  16. arr[b+1] = temp;
  17. }
  18. }
  19. }
  20.  
  21. for (int cnt = 0; cnt < SIZE; cnt++){
  22. cout << arr[cnt] << " ";
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement