diff --git a/main.cpp b/main.cpp index 00b60e9..945c47e 100644 --- a/main.cpp +++ b/main.cpp @@ -11,29 +11,88 @@ using namespace std; -const long MAXN = 1e4; +//const size_t MAXN = (size_t)1e3; //size of YT +const double EPS = 1e-8; long long factorial[20]; //const unsigned int N = 5; -long double branch_prob[MAXN]; +//long double branch_prob[MAXN]; int main() { - //freopen("out.txt", "w", stdout); - freopen("err.txt", "w", stderr); + freopen("out.txt", "w", stdout); + //freopen("err.txt", "w", stderr); + cout.precision(6); - long b[10]; - for (int i = 0; i < 10; ++i) + /* + double add = 1 / (double)MAXN; + double r = 0; + for (size_t i = 0; i < MAXN; ++i) + { + ra[i] = r; + r += add; + } + + rand_permute_self_inverse(ra, MAXN); + */ + + const long MAN = (long)2e2; + long *func = new long[MAN]; + long *height = new long[MAN]; + long *length = new long[MAN]; + for (size_t MAXN = 1; MAXN < MAN; ++MAXN) { - b[i] = i; - cout << i << ' '; + cerr << MAXN << "\n"; + double *ra = 0; + ra = new double[MAXN]; + rand_arr(ra, MAXN); + PQ_tableaux PQ; + PQ.push(ra, MAXN); + height[MAXN] = PQ.height(); + length[MAXN] = PQ.length(); + + double *max_ra = new double[MAXN]; + for (size_t cnt = 0; cnt * cnt < 16 * MAXN; ++cnt) + { + for (size_t i = 0; i < MAXN; ++i) + { + double tmp = 0; + for (size_t j = 0; j < i; ++j) + { + tmp = max(tmp, (ra[j] < ra[i]) ? ra[j] : 0); + } + max_ra[i] = tmp; + } + PQ_tableaux PQ_max; + PQ_max.push(max_ra, MAXN); + if (PQ_max.height() == 1) + { + func[MAXN] = cnt; + break; + } + for (size_t i = 0; i < MAXN; ++i) + { + ra[i] = max_ra[i]; + } + } } - cout << "\n"; - rand_permute_self_inverse(b, 10); - for (int i = 0; i < 10; ++i) + + for (size_t i = 0; i < MAN; ++i) { - cout << b[i] << ' '; + cout << i << ' ' << func[i] << ' ' << length[i] << ' ' << height[i] << "\n"; } - cout << "\n"; + + /* + PQ.showP(); + cout << "\n\n"; + PQ.truncate(max_ra[9], ra[9]); + PQ.showP(); + cout << "\n\n"; + PQ.truncate(max_ra[89], ra[89]); + PQ.showP(); + cout << "\n\n"; + */ + + /* int n = 6000; @@ -97,7 +156,7 @@ int main() { cout << "id_points statistics for all permutation: " << measure << "\n" << "\n"; } */ - system("pause"); + //system("pause"); return 0; /* PQ_tableaux PQ; diff --git a/my_vector.h b/my_vector.h new file mode 100644 index 0000000..8417e62 --- /dev/null +++ b/my_vector.h @@ -0,0 +1,49 @@ +#pragma once +#include +#include + +using namespace std; + +template +ostream& operator <<(ostream&, const vector&); //Output operator for vector +template +vector operator +( + const vector &, + const vector & + ); +template +T sum(const vector &); + + + +//implementation + +template +ostream& operator <<(ostream& os, const vector& out) +{ + for (auto i : out) + { + os << i << ' '; + } + return os; +} +template +vector operator+(const vector & vec1, const vector & vec2) +{ + vector vec_res(max(vec1.size(), vec2.size())); + for (int i = 0; i < (int)min(vec1.size(), vec2.size()); ++i) + { + vec_res[i] = vec1[i] + vec2[i]; + } + return vec_res; +} +template +T sum(const vector& vec) +{ + T sum = 0; + for (auto i : vec) + { + sum += i; + } + return sum; +} \ No newline at end of file diff --git a/permutations.cpp b/permutations.cpp new file mode 100644 index 0000000..8699c19 --- /dev/null +++ b/permutations.cpp @@ -0,0 +1,15 @@ +#include +#include "permutations.h" +#include + +using namespace std; + +void init_involution_branch_prob(long double * b, long n) //count branch prob. for involutions +{ + b[1] = 1; + for (int i = 1; i < n; ++i) + { + b[i + 1] = 1 / (1 + i * b[i]); + } + return; +} \ No newline at end of file diff --git a/permutations.h b/permutations.h new file mode 100644 index 0000000..6e923d8 --- /dev/null +++ b/permutations.h @@ -0,0 +1,93 @@ +#pragma once + +#include +#include "random.h" + +using namespace std; + +template +void permutate(vector &, const vector &); //Apply permutation to vector +template +int count_identity_points(vector &); //Count the number of identity points +template +inline void rand_permute_self_inverse( + T*, long, long *, + long double *, bool); //Return involution of length n +void init_involution_branch_prob(long double*, long); //Count branch probabilities for generating random involution + + + +//implementation + + +template +void permutate(vector& value, const vector& permutation) +{ + auto new_value = value; + for (int i = 0; i < (int)value.size(); ++i) + { + new_value[permutation[i]] = value[i]; + } + for (int i = 0; i < (int)value.size(); ++i) + { + value[i] = new_value[i]; + } + return; +} +template +int count_identity_points(vector& vec) +{ + vector> new_vec(vec.size()); + for (int i = 0; i < (int)vec.size(); ++i) + { + new_vec[i] = { vec[i], i }; + } + sort(new_vec.begin(), new_vec.end()); + int identity_points = 0; + for (int i = 0; i < (int)vec.size(); ++i) + { + identity_points += new_vec[i].second == i; + } + return identity_points; +} +template //not finished yet, destructor needs some treatment +void rand_permute_self_inverse(T *f, long n, + long *tr = 0, + long double *tb = 0, bool bi = false) + // Permute the elements of f by a random involution. + // Set bi:=true to signal that the branch probabilities in tb[] + // have been precomputed (via init_involution_branch_ratios()). +{ + long *r = tr; + if (tr == 0) r = new long[n]; + for (long k = 0; k < n; ++k) r[k] = k; + long nr = n; // number of elements available + // available positions are r[0], ..., r[nr-1] + + long double *b = tb; + if (tb == 0) { b = new long double[n]; bi = false; } + if (!bi) init_involution_branch_prob(b, n); + + while (nr >= 2) + { + const long x1 = nr - 1; // choose last element + const long r1 = r[x1]; // available position + // remove from set: + --nr; // no swap needed if x1==last + + const long double rat = b[nr]; // probability to choose fixed point + + const long double t = rand01(); // 0 <= t < 1 + if (t > rat) // 2-cycle + { + const long x2 = randN(nr); + const long r2 = r[x2]; // random available position != r1 + --nr; swap(r[x2], r[nr]); // remove from set + swap(f[r1], f[r2]); // create a 2-cycle + } + // else fixed point, nothing to do + } + + //if (tr == 0) delete[] r; + //if (tb == 0) delete[] b; +} \ No newline at end of file diff --git a/random.cpp b/random.cpp new file mode 100644 index 0000000..e5fbeac --- /dev/null +++ b/random.cpp @@ -0,0 +1,30 @@ + +#include +#include +#include "random.h" + +using namespace std; + +long randN(long N) +{ + long tmp = rand() ^ (rand() << 16); + return tmp % N; +} +double rand01(double acc) +{ + static bool f = false; + if (!f) + { + double tme = (double)time(NULL); + srand(tme); + f = true; + } + double rand_num = ((rand() ^ (rand() << 16)) % (int)acc) / acc; + return rand_num; +} +void rand_arr(double *ra, size_t n) +{ + for (size_t i = 0; i < n; i++) + ra[i] = rand01(); + return; +} diff --git a/random.h b/random.h new file mode 100644 index 0000000..43b35dc --- /dev/null +++ b/random.h @@ -0,0 +1,7 @@ +#pragma once + + + +double rand01(double acc = 1e6); //Return real random number from [0, 1] +long randN(long); //Return integer random number from [0, N-1], where N is an argument +void rand_arr(double *, size_t); //Return an array of real random numbers form [0, 1] \ No newline at end of file diff --git a/young.cpp b/young.cpp index b0225ca..fd082e8 100644 --- a/young.cpp +++ b/young.cpp @@ -1,312 +1,26 @@ #include -#include #include #include -#include #include "young.h" +#include "permutations.h" +#include "random.h" +#include "my_vector.h" #include -#include using namespace std; -int Row::size() { - return _row.size(); -} -double Row::reverse_Shensted_insert(double x) -{ - auto y = (--_row.lower_bound(x)); - double new_x = *y; - _row.erase(y); - _row.insert(x); - return new_x; -} -double Row::Shensted_insert(double x) -{ - auto y = _row.upper_bound(x); - if (y == _row.end()) { - _row.insert(x); - return -1; - } - double new_x = *y; - _row.erase(y); - _row.insert(x); - return new_x; -} -double Row::pop() -{ - int elem = *(--_row.end()); - _row.erase((--_row.end())); - return elem; -} -bool Row::find(double x) -{ - return (_row.find(x) != _row.end()); -} -ostream& operator<<(ostream& out, Row& obj) { - for (auto it : obj._row) - out << it << ' '; - return out; -} -ostream & operator<<(ostream & out, Tableau & T) -{ - for (auto it : T._tableau) - if (it.size() != 0) - out << it << "\n"; - return out; - // TODO: âñòàâüòå çäåñü îïåðàòîð return -} -void print_collection_of_Tableau(vector vect_T) -{ - int max_height = 0; - for (auto it : vect_T) - { - max_height = max(max_height, it.size()); - } - for (int tmp_row = 0; tmp_row < max_height; ++tmp_row) - { - for (auto it : vect_T) - { - } - } -} -ostream & operator<<(ostream & out, PQ_tableaux & PQ) -{ - out << "P:\n" << PQ._P << "Q:\n" << PQ._Q; - return out; - // TODO: âñòàâüòå çäåñü îïåðàòîð return -} -Row::Row(vector row) { - for (auto it : row) - this->_row.insert(it); -} +//class Row -int Tableau::push(double elem) -{ - int count = 0; - for (auto & it : _tableau) - { - auto new_elem = it.Shensted_insert(elem); - elem = new_elem; - if (new_elem == -1) - break; - count++; - } - if (elem != -1) - { - _tableau.push_back(Row({ elem })); - } - _size++; - return count; -} -void Tableau::insert(int row, double x) -{ - if (row >= _tableau.size()) - _tableau.push_back(Row()); - _tableau[row].Shensted_insert(x); -} -void Tableau::push(vector elems) -{ - for (auto it : elems) - push(it); -} +//class Tableau -int Tableau::size() -{ - return _size; -} -double Tableau::pop(int row) -{ - return _tableau[row].pop(); -} +//class PQ-tableaux -double Tableau::erase(int tmp_row) -{ - double tmp_x = pop(tmp_row); - for (int i = tmp_row - 1; i >= 0; --i) - { - tmp_x = _tableau[i].reverse_Shensted_insert(tmp_x); - } - return tmp_x; -} -int Tableau::find(double x) -{ - for (int i = 0; i < _tableau.size(); i++) - if (_tableau[i].find(x)) - return i; - return -1; -} -vector Tableau::type() -{ - vector type; - for (int i = 0; i < _tableau.size(); ++i) - { - type.push_back(_tableau[i].size()); - } - return type; -} -void PQ_tableaux::push(double elem) -{ - int changed_row = _P.push(elem); - int size = _P.size(); - _Q.insert(changed_row, size); - _row_number.push_back(changed_row); -} - -void PQ_tableaux::push(vector elems) -{ - for (auto it : elems) - push(it); -} - -double PQ_tableaux::pop() -{ - int row = _row_number[_row_number.size() - 1]; - _row_number.pop_back(); - _Q.pop(row); - return _P.pop(row); -} - -double PQ_tableaux::erase() -{ - int tmp_row = _row_number[_row_number.size() - 1]; - double new_x = _P.erase(tmp_row); - _Q.pop(tmp_row); - _row_number.pop_back(); - return new_x; -} - -void PQ_tableaux::showQ() -{ - - cout << "Q:\n" << _Q; -} - -void PQ_tableaux::showP() -{ - cout << "P:\n" << _P; -} - -int PQ_tableaux::size() -{ - return _P.size(); - return 0; -} -int PQ_tableaux::find(double x) -{ - return(_P.find(x)); -} -vector PQ_tableaux::type() -{ - return _P.type(); -} -double rand_num() { - double x = ((rand() ^ (rand() << 16)) % 1000000) / 1000000.0; - return x; -} -vector rand_vec(int n){ - vector vec; - for (int i = 0; i < n; i++) - vec.push_back(rand_num()); - return vec; -} - - -void permutate(vector& value, const vector& permutation) -{ - auto new_value = value; - for (int i = 0; i < (int)value.size(); ++i) - { - new_value[permutation[i]] = value[i]; - } - for (int i = 0; i < (int)value.size(); ++i) - { - value[i] = new_value[i]; - } - return; -} - -int count_identity_points(vector& vec) -{ - vector> new_vec(vec.size()); - for (int i = 0; i < (int)vec.size(); ++i) - { - new_vec[i] = { vec[i], i }; - } - sort(new_vec.begin(), new_vec.end()); - int identity_points = 0; - for (int i = 0; i < (int)vec.size(); ++i) - { - identity_points += new_vec[i].second == i; - } - return identity_points; -} -int sum(const vector& vec) -{ - double sum = 0; - for (auto i : vec) - { - sum += i; - } - return sum; -} -long randN(long N) -{ - long tmp = rand() ^ (rand() << 16); - return tmp % N; -} -long double rand01() -{ - static bool f = false; - if (!f) - { - double tme = time(NULL); - srand(tme); - f = true; - } - double rand_num = ((rand() ^ (rand() << 16)) % 100000) / 100000.0; - return rand_num; -} -void init_involution_branch_prob(long double * b, long n) //count branch prob. for involutions -{ - b[1] = 1; - for (int i = 1; i < n; ++i) - { - b[i + 1] = 1 / (1 + i * b[i]); - } - return; -} -ostream& operator <<(ostream& os, const vector& out) -{ - for (auto i : out) - { - os << i << ' '; - } - return os; -} -ostream& operator <<(ostream& os, const vector& out) -{ - for (auto i : out) - { - os << i << ' '; - } - return os; -} - -vector operator+(const vector & vec1, const vector & vec2) -{ - vector vec_res(max(vec1.size(), vec2.size())); - for (int i = 0; i < (int)min(vec1.size(), vec2.size()); ++i) - { - vec_res[i] = vec1[i] + vec2[i]; - } - return vec_res; -} diff --git a/young.h b/young.h index e859975..38fc5ce 100644 --- a/young.h +++ b/young.h @@ -1,124 +1,406 @@ #pragma once +#include +#include #include #include +#include "permutations.h" +#include "random.h" + +#define space8 " " +#define INF (int)1e8 using namespace std; +template class Row { //Row of Young tableau consisting of real numbers public: - Row() {} - Row(vector ); - int size(); - double reverse_Shensted_insert(double); //Reverse bumping - friend ostream& operator<<(ostream&, Row&); //Printing the row - double Shensted_insert(double); //Classical row bumping - double pop(); //Delete the bigest element and return it - bool find(double x); //Return is there such an element + Row() : + _left_bound(-INF), + _right_bound(INF) + {} + Row(T); + Row(T *, size_t n); + size_t size(); //Return size of row + T reverse_Shensted_insert(T); //Reverse bumping + friend ostream& operator<<( //Printing the row + ostream& out, + Row& obj + ) + { + auto ind_low = obj._row.upper_bound(obj._left_bound); + auto ind_upper = obj._row.upper_bound(obj._right_bound); + for (auto it = obj._row.begin(); it != ind_low; ++it) + { + //out << space8 << " \t"; + out << " "; + } + out << setprecision(6) << fixed; + for (auto it = ind_low; it != ind_upper; ++it) + { + //out << *it << " \t"; + out << "0"; + } + for (auto it = ind_upper; it != obj._row.end(); ++it) + { + out << "#"; + } + return out; + } + void truncate(T, T); + void untruncate(); + T Shensted_insert(T); //Classical row bumping + T pop(); //Delete the bigest element and return it + bool find(T x); //Return is there such an element private: - multiset _row; + multiset _row; + T _left_bound, _right_bound; }; - +template class Tableau // Young Tableau { public: - Tableau() : _size(0) {} - int push(double); //Insert an element in the tableau - void insert(int, double); //Tnsert an element in the row of the tableau - void push(vector); //Insert several elements in given order - friend ostream& operator<<(ostream&, Tableau&); //Print the tableau - friend void print_collection_of_Tableau(vector); //Print the collection of tableaux - int size(); - double pop(int); //Delete the bigest an element from the row - double erase(int); //Reverse bumping from the tableau - int find(double); //Return the minimal number of a row which contains the element or -1 if there is not such a row - vector type(); + Tableau() : + _size(0) + {} + size_t push(T); //Insert an element in the tableau + void insert(size_t, T); //Tnsert an element in the row of the tableau + void push(T *, size_t); //Insert several elements in given order + friend ostream & operator<<( //Print the tableau + ostream & out, + Tableau & T + ) + { + for (auto it : T._tableau) + { + if (it.size() != 0) + out << it << "\n"; + } + return out; + } + friend void print_collection_of_Tableau( + vector>); //Print the collection of tableaux + size_t size(); + size_t height(); + size_t length(); + void truncate(T, T); + void untruncate(); + T pop(size_t); //Delete the bigest an element from the row + T erase(size_t); //Reverse bumping from the tableau + int find(T); //Return the minimal number of a row which contains the element or -1 if there is not such a row + void type(size_t *); private: - vector _tableau; - int _size; + vector> _tableau; + size_t _size; }; - -class PQ_tableaux //Pair of inserting and recording Young tableaux +template +class PQ_tableaux //Pair of recording and numerating Young tableaux { public: - void push(double); //Insert the element in inserting tableau and its counting number in recording tableau - void push(vector ); //Insert several elements in given order in the way describing ... - double pop(); //Delete the element and its pair from the given row - double erase(); //Reverse bumping from the pair of tableaux - friend ostream& operator<<(ostream&, PQ_tableaux&); //Print the pair of tableaux - void showQ(); //Print only recording tableau - void showP(); - int size(); - int find(double); - vector type(); + void push(T); //Insert the element in inserting tableau and its counting number in recording tableau + void push(T *, size_t n); //Insert several elements in given order in the way describing ... + T erase(); //Reverse bumping from the pair of tableaux + friend ostream & operator<<( //Print the pair of tableaux + ostream & out, + PQ_tableaux & PQ + ) + { + out << "P:\n" << PQ._P << "Q:\n" << PQ._Q; + return out; + } + void truncate(T, T); + void untruncate(); + void showQ(); //Print numerating tableau + void showP(); //Print recording tableau + size_t size(); //Return size of tableau + size_t height(); + size_t length(); + int find(T); //Return the least row containing given element + void type(size_t *); //Put the type of tableau in given array private: - Tableau _P, _Q; - vector _row_number; + Tableau _P, _Q; + vector _row_number; }; -double rand_num(); -vector rand_vec(int); - -ostream& operator <<(ostream&, const vector&); //Output operator for vector -ostream& operator <<(ostream&, const vector&); //Output operator for vector -//class template ; -vector operator +( - const vector &, - const vector & - ); -void permutate(vector &, const vector &); //Apply permutation to vector -int count_identity_points(vector&); //Count the number of identity points -int sum(const vector&); -long double rand01(); //Return random number from [0, 1] -long randN(long N); -template -inline void rand_permute_self_inverse( - T*, long, long *, - long double *, bool); //Return involution of length n -void init_involution_branch_prob(long double*, long); //Count branch probabilities for generating random involution //implementation -template //not finished yet, надо что-то с деструктором сделать -inline void rand_permute_self_inverse(T *f, long n, - long *tr = 0, - long double *tb = 0, bool bi = false) - // Permute the elements of f by a random involution. - // Set bi:=true to signal that the branch probabilities in tb[] - // have been precomputed (via init_involution_branch_ratios()). -{ - long *r = tr; - if (tr == 0) r = new long[n]; - for (long k = 0; k < n; ++k) r[k] = k; - long nr = n; // number of elements available - // available positions are r[0], ..., r[nr-1] - long double *b = tb; - if (tb == 0) { b = new long double[n]; bi = false; } - if (!bi) init_involution_branch_prob(b, n); +//class Row +template +Row::Row(T elem) +{ + _left_bound = -INF; + _right_bound = INF; + this->_row.insert(elem); +} +template +Row::Row(T *row, size_t n) +{ + _left_bound = -INF; + _right_bound = INF; + for (size_t i = 0; i < n; ++i) + this->_row.insert(row[i]); +} +template +T Row::reverse_Shensted_insert(T x) +{ + auto y = (--_row.lower_bound(x)); + double new_x = *y; + _row.erase(y); + _row.insert(x); + return new_x; +} +template +T Row::Shensted_insert(T x) +{ + auto y = _row.upper_bound(x); + if (y == _row.end()) { + _row.insert(x); + return -1; + } + T new_x = *y; + _row.erase(y); + _row.insert(x); + return new_x; +} +template +T Row::pop() +{ + auto elem = *(--_row.end()); + _row.erase((--_row.end())); + return elem; +} +template +bool Row::find(T x) +{ + return (_row.find(x) != _row.end()); +} +template +size_t Row::size() { + return _row.size(); +} +template +void Row::truncate(T trunc_low, T trunc_upper) +{ + _left_bound = trunc_low; + _right_bound = trunc_upper; + return; +} +template +void Row::untruncate() +{ + _left_bound = -INF; + _right_bound = INF; + return; +} + - while (nr >= 2) +//class Tableau +template +void print_collection_of_Tableau(vector> vect_T) +{ + size_t max_height = 0; + for (auto it : vect_T) { - const long x1 = nr - 1; // choose last element - const long r1 = r[x1]; // available position - // remove from set: - --nr; // no swap needed if x1==last - - const long double rat = b[nr]; // probability to choose fixed point - - const long double t = rand01(); // 0 <= t < 1 - if (t > rat) // 2-cycle + max_height = max(max_height, it.size()); + } + for (int tmp_row = 0; tmp_row < max_height; ++tmp_row) + { + for (auto it : vect_T) { - const long x2 = randN(nr); - const long r2 = r[x2]; // random available position != r1 - --nr; swap(r[x2], r[nr]); // remove from set - swap(f[r1], f[r2]); // create a 2-cycle + } - // else fixed point, nothing to do } +} +template +size_t Tableau::push(T elem) +{ + size_t row = 0; + for (auto & it : _tableau) + { + auto new_elem = it.Shensted_insert(elem); + elem = new_elem; + if (new_elem == -1) + break; + row++; + } + if (elem != -1) + { + Row row(elem); + _tableau.push_back(Row(elem)); + } + _size++; + return row; +} +template +void Tableau::insert(size_t row, T x) +{ + if (row >= _tableau.size()) + _tableau.push_back(Row()); + _tableau[row].Shensted_insert(x); + _size++; + return; +} +template +void Tableau::push(T *elems, size_t n) +{ + for (size_t i = 0; i < n; ++i) + { + push(elems[i]); + } +} +template +T Tableau::pop(size_t row) +{ + return _tableau[row].pop(); +} +template +T Tableau::erase(size_t tmp_row) +{ + double tmp_x = pop(tmp_row); + for (int i = (int)tmp_row - 1; i >= 0; --i) + { + tmp_x = _tableau[i].reverse_Shensted_insert(tmp_x); + } + return tmp_x; +} +template +int Tableau::find(T x) +{ + for (size_t i = 0; i < _tableau.size(); i++) + if (_tableau[i].find(x)) + return (int)i; + return -1; +} +template +size_t Tableau::size() +{ + return _size; +} +template +size_t Tableau::height() +{ + return _tableau.size(); +} +template +size_t Tableau::length() +{ + if (_tableau.empty()) + { + return 0; + } + return _tableau[0].size(); +} +template +void Tableau::type(size_t *type) +{ + type = new size_t[_tableau.size()]; + for (size_t i = 0; i < _tableau.size(); ++i) + { + type[i] = _tableau[i].size(); + } + return; +} +template +void Tableau::truncate(T trunc_low, T trunc_upper) +{ + for (auto it = _tableau.begin(); it != _tableau.end(); ++it) + { + it->truncate(trunc_low, trunc_upper); + } + return; +} +template +void Tableau::untruncate() +{ + for (auto it : _tableau) + { + it.untruncate(); + } + return; +} + - //if (tr == 0) delete[] r; - //if (tb == 0) delete[] b; +//class PQ_tableaux +template +void PQ_tableaux::push(T elem) +{ + size_t changed_row = _P.push(elem); + size_t size = _P.size(); + _Q.insert(changed_row, size); + _row_number.push_back(changed_row); +} +template +void PQ_tableaux::push(T *elems, size_t n) +{ + for (size_t i = 0; i < n; ++i) + { + push(elems[i]); + } +} +template +T PQ_tableaux::erase() +{ + if (_row_number.empty()) + { + cerr << "Try to delete element from empty tableau.\n"; + return 0; + } + size_t tmp_row = _row_number[_row_number.size() - 1]; + T new_x = _P.erase(tmp_row); + _Q.pop(tmp_row); + _row_number.pop_back(); + return new_x; +} +template +int PQ_tableaux::find(T x) +{ + return(_P.find(x)); +} +template +void PQ_tableaux::type(size_t * type) +{ + _P.type(type); + return; +} +template +size_t PQ_tableaux::size() +{ + return _P.size(); +} +template +size_t PQ_tableaux::height() +{ + return _P.height(); +} +template +size_t PQ_tableaux::length() +{ + return _P.length(); +} +template +void PQ_tableaux::showQ() +{ + + cout << "Q:\n" << _Q; +} +template +void PQ_tableaux::showP() +{ + cout << "P:\n" << _P; +} +template +void PQ_tableaux::truncate(T trunc_low, T trunc_upper) +{ + _P.truncate(trunc_low, trunc_upper); + return; +} +template +void PQ_tableaux::untruncate() +{ + _P.untruncate(); + return; } \ No newline at end of file