Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main() {
- int anzEle=10;
- int sorted[anzEle];
- int reversed[anzEle];
- int random[anzEle];
- for(int i=0; i<anzEle; ++i) {
- sorted[i]=i;
- reversed[i]=anzEle-i-1;
- random[i]=rand();
- }
- for(int i=0; i<anzEle; ++i)
- cout<<random[i]<<"\n";
- for(int i=1; i<anzEle; ++i) {
- bool atLeastOneSwap=false;
- for(int j=0; j<anzEle-i; ++j) {
- if(random[j]>random[j+1]) {
- int tmp=random[j];
- random[j]=random[j+1];
- random[j+1]=tmp;
- atLeastOneSwap=true;
- }
- }
- if(!atLeastOneSwap) {
- return 0;
- }
- }
- for(int i=0; i<anzEle; ++i)
- cout<<random[i]<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement