Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void BubbleSort (int arr[], int n)
- {
- int i, j;
- for (i = 0; i < n; ++i)
- {
- for (j = 0; j < n-i-1; ++j)
- {
- if (arr[j] > arr[j+1])
- {
- arr[j] = arr[j]+arr[j+1];
- arr[j+1] = arr[j]-arr[j + 1];
- arr[j] = arr[j]-arr[j + 1];
- }
- }
- }
- }
- int main()
- {
- int n, i;
- cout<<"n=";
- cin>>n;
- int arr[n];
- for(i = 0; i < n; i++)
- {
- cout<<"n"<<i+1<<": ";
- cin>>arr[i];
- }
- BubbleSort(arr, n);
- cout<<"V[n]=";
- for (i = 0; i < n; i++)
- cout<<" "<<arr[i];
- return 0;
- }
Add Comment
Please, Sign In to add comment