Sfoglia il codice sorgente

Change permutation.sigma into vector<int>

Olivier Marty 8 anni fa
parent
commit
be038e79f9
2 ha cambiato i file con 5 aggiunte e 3 eliminazioni
  1. 1 2
      src/permutation.cpp
  2. 4 1
      src/permutation.h

+ 1 - 2
src/permutation.cpp

@@ -3,9 +3,8 @@
 #include <cstdlib> // rand
 #include <cassert>
 
-permutation::permutation(int size) : size(size) {
+permutation::permutation(int size) : size(size), sigma(size) {
   assert(size > 0);
-  sigma = new int[size];
   for(int i = 0; i < size; i++)
     sigma[i] = i;
 }

+ 4 - 1
src/permutation.h

@@ -1,6 +1,8 @@
 #ifndef PERMUTATION_H
 #define PERMUTATION_H
 
+#include <vector>
+
 // permutation with fixpoint pi[0]=0
 class permutation {
   public:
@@ -9,7 +11,8 @@ class permutation {
     void random();
     int operator[](int i); // return the image of i (i and its image 0-based)
   protected:
-    int *sigma, size; // data[i] is the image of i
+    int size;
+    std::vector<int> sigma; // sigma[i] is the image of i
 };
 
 #endif // PERMUTATION_H