Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int x[6] = {2, 8, 1, 5, 6, 4};
- int n = 6;
- void afis(){
- cout << '\n';
- for(int i=0; i<n; i++)
- cout << x[i] << ' ';
- }
- void sch(int &a, int &b){
- int aux;
- aux = a;
- a = b;
- b = aux;
- }
- void bubble_sort(int x[]){
- bool swapped = true;
- int j = 0, p = 1;
- while(swapped) {
- cout << "\n\nParcurgere " << p++;
- swapped = false;
- j++;
- for(int i = 0; i<n-j; i++){
- if(x[i] > x[i+1]){
- sch(x[i], x[i+1]);
- swapped = true;
- afis();
- }
- }
- }
- }
- int main()
- {
- afis();
- bubble_sort(x);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement