Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int anzEle=10;
  8.     int sorted[anzEle];
  9.     int reversed[anzEle];
  10.     int random[anzEle];
  11.     for(int i=0; i<anzEle; ++i) {
  12.         sorted[i]=i;
  13.         reversed[i]=anzEle-i-1;
  14.         random[i]=rand();
  15.     }
  16.  
  17.     for(int i=0; i<anzEle; ++i)
  18.         cout<<random[i]<<"\n";
  19.  
  20.     for(int i=1; i<anzEle; ++i) {
  21.         bool atLeastOneSwap=false;
  22.         for(int j=0; j<anzEle-i; ++j) {
  23.                 if(random[j]>random[j+1]) {
  24.                     int tmp=random[j];
  25.                     random[j]=random[j+1];
  26.                     random[j+1]=tmp;
  27.                     atLeastOneSwap=true;
  28.                 }
  29.         }
  30.         if(!atLeastOneSwap) {
  31.             return 0;
  32.         }
  33.     }
  34.  
  35.     for(int i=0; i<anzEle; ++i)
  36.         cout<<random[i]<<"\n";
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement