خرید بک لینک

Vote count: 0

Its been a while since I have worked with classes, im slowly getting back into the mix. I have this Bogo Sort and I see it loop a bunch of time right after "int center" in the bogosort function. Can anyone help me figure out why exactly it gets stuck at the next calling function. I made sure I made &left and &right constants.

#include <algorithm>
#include <vector>
#include <iostream>
#include <iterator>
using namespace std;



void bogosort(vector<int> & a, const int &left, const int &right) {

int center = (left + right) / 2;

bogosort(a, left, center);

bogosort(a, center + 1, right);
cout << "good";
if (a[center] > a[right]) {
    swap(a[center], a[right]);
}
bogosort(a, left, right - 1);

//retu 0;
}


int main() {
vector<int> myVector;
vector<int>::iterator it;

myVector = { 100, 2, 5, 52, 13, 55, 89, 14, 1, 99 };
int left = 0;
int right = 9;
//int fs;
for (it = myVector.begin(); it != myVector.end(); ++it) {
    cout << ' ' << *it;
}

bogosort(myVector, left, right);

for (it = myVector.begin(); it != myVector.end(); ++it) {
    cout << ' ' << *it;
}
retu 0;
}

asked 2 mins ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 29 بهمن 1394 ساعت: 9:30

صفحه بندی