Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array Sorting, effective method (Bubble-Sort)
- #include <iostream>
- #include <iomanip>>
- using namespace std;
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- int main() {
- int temp;
- int n = 4;
- int arr[n] = {7, 8, 2, 1};
- for(int x = 0; x < n; x++)
- {
- for(int k = 0; k < n; k++)
- {
- if(arr[k] > arr[k + 1])
- {
- temp = arr[k];
- arr[k] = arr[k + 1];
- arr[k + 1] = temp;
- }
- }
- }
- for(int c = 0; c < n; c++)
- cout << arr[c] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement