Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include "b_sort.h"
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. bool checking(int count, b_sort *sortClass)
  8. {
  9.     bool test[25];
  10.     unsigned int mask;
  11.     bool correct = true;
  12.  
  13.     for (int i = 0; i < (int)pow(2.0, count); ++i) {
  14.         mask = 1;
  15.         for (int j = count - 1; j >=0 ; j--) {
  16.             if (i & mask > 0) {
  17.                 test[j] = true;
  18.             } else {
  19.                 test[j] = false;
  20.             }
  21.             mask = mask << 1;
  22.         }
  23.         sortClass->currentComp = sortClass->firstComp;
  24.         while (sortClass->currentComp != NULL)
  25.         {
  26.             if (test[sortClass->currentComp->first] != test[sortClass->currentComp->second] &&
  27.                 test[sortClass->currentComp->first]) {
  28.                 test[sortClass->currentComp->first] = false;
  29.                 test[sortClass->currentComp->second] = true;
  30.             }
  31.             sortClass->currentComp = sortClass->currentComp->next;
  32.         }
  33.         for (int j = 0; j < count -1; j++) {
  34.             if (test[j] != test[j + 1] && test[j]) {
  35.                 return false;
  36.             }
  37.         }
  38.     }
  39.     return true;
  40.  
  41. }
  42.  
  43. int main(int argc, char* argv[])
  44. {
  45.     unsigned int count, first = 0, step = 1, tacts;
  46.     b_sort *sortClass = new b_sort();
  47.     bool good = true;
  48.  
  49.     if (argc >= 2) {
  50.         count = atoi(argv[1]);
  51.     } else {
  52.         cout << "No arguments" << endl;
  53.         return -1;
  54.     }
  55.  
  56.     cout << count << " 0 0" << endl;
  57.     tacts = sortClass->sort(first, step, count);
  58.  
  59.     //good = checking(count, sortClass);
  60.  
  61.     sortClass->currentComp = sortClass->firstComp;
  62.     while (sortClass->currentComp != NULL)
  63.     {
  64.         cout << sortClass->currentComp->first << ' ' << sortClass->currentComp->second << endl;
  65.         sortClass->currentComp = sortClass->currentComp->next;
  66.     }
  67.     cout << sortClass->count << "\n" << tacts << endl;
  68.  
  69.     //cout << good << endl;
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement