Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void printElementsCntPerCycle(int *permutation, int *universal, int size) {
- int elementsPerIndependentCycle[size]{0};
- int currentIndependentCycle = 0;
- int cyclesCnt = 0;
- int passedIndexes[size]{0};
- int wantedIndex = 0;
- int wanted = universal[wantedIndex];
- int operatingIndex = 0;
- int upElement = universal[operatingIndex];
- int downElement = permutation[operatingIndex];
- while (cyclesCnt < size) {
- elementsPerIndependentCycle[currentIndependentCycle]++;
- while (downElement != wanted) {
- elementsPerIndependentCycle[currentIndependentCycle]++;
- passedIndexes[operatingIndex] = -1;
- operatingIndex = getIndex(universal, size, downElement);
- upElement = universal[operatingIndex];
- downElement = permutation[operatingIndex];
- cyclesCnt++;
- }
- currentIndependentCycle++;
- passedIndexes[operatingIndex] = -1;
- operatingIndex = getFirstFreeIndex(passedIndexes, size);
- if (operatingIndex == -1) {
- break;
- }
- wanted = universal[operatingIndex];
- upElement = universal[operatingIndex];
- downElement = permutation[operatingIndex];
- }
- for(int i = 0; i < currentIndependentCycle; i++){
- cout << "Cycle " << i + 1 << " has " << elementsPerIndependentCycle[i] << " elements." << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement