Answer to Question #3276 in C++ for Jakir
2011-06-30T12:33:20-04:00
I want to get some examples of Bubble short program of C++
1
2011-07-01T11:13:02-0400
#include //bubble sort void bubbleSort(int mas[], const int n){ for(int i = 0; i < n; i++){ for(int o = 0; o < n-1-i; o++){ if(mas[o] > mas[o+1]){ //swap elements int x = mas[o]; mas[o] = mas[o+1]; mas[o+1] = x; } } } } int main(){ int n; printf("Input quantity: "); scanf("%d",&n); if(n<=0){ return 0; } int* mas = new int[n]; //Enter numbers printf("Enter numbers "); for(int i = 0; i < n; i++){ scanf("%d",&mas[i]); } //sort numbers bubbleSort(mas,n); //print sorted array printf("Result: "); for(int i = 0; i < n; i++){ printf("%d ",mas[i]); } return 0; }
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS !
Learn more about our help with Assignments:
C++
Comments
Leave a comment