12 #ifndef __PERMUTE_HH__
13 #define __PERMUTE_HH__
36 template <
class B
idirIt>
39 while ((first != last) && (first != --last))
40 swap(*first++, *last);
45 template <
class B
idirIt>
51 for (BidirIt i = first; i != last; ++i)
53 std::cout << std::endl;
60 for (BidirIt i1 = fixPos; i1 != last; ++i1)
66 for (BidirIt i2 = fixPos; i2 < i1; ++i2)
92 template <
class B
idirIt>
105 SnapShotStruct currentSnapshot;
106 currentSnapshot.first = first;
107 currentSnapshot.fixPos = fixPos;
108 currentSnapshot.last = last;
109 currentSnapshot.i1 = fixPos;
110 currentSnapshot.stage = 0;
111 snapshotStack.
push(currentSnapshot);
113 while (!snapshotStack.
isEmpty())
115 currentSnapshot = snapshotStack.
top();
118 switch (currentSnapshot.stage)
122 if (currentSnapshot.fixPos == currentSnapshot.last)
124 for (BidirIt i = currentSnapshot.first; i != currentSnapshot.last; ++i)
126 std::cout << std::endl;
131 currentSnapshot.stage = 1;
132 snapshotStack.
push(currentSnapshot);
138 if (currentSnapshot.i1 == currentSnapshot.last)
142 for (BidirIt i2 = currentSnapshot.fixPos; i2 < currentSnapshot.i1; ++i2)
144 if (*currentSnapshot.i1 == *i2)
152 ++currentSnapshot.i1;
153 currentSnapshot.stage = 1;
154 snapshotStack.
push(currentSnapshot);
158 swap(*currentSnapshot.i1, *currentSnapshot.fixPos);
160 currentSnapshot.stage = 2;
161 snapshotStack.
push(currentSnapshot);
164 currentSnapshot.i1 = ++currentSnapshot.fixPos;
165 currentSnapshot.stage = 0;
166 snapshotStack.
push(currentSnapshot);
172 swap(*currentSnapshot.i1, *currentSnapshot.fixPos);
174 ++currentSnapshot.i1;
175 currentSnapshot.stage = 1;
176 snapshotStack.
push(currentSnapshot);
189 throw(std::string{
"Empty container!\n"});
200 throw(std::string{
"Empty container!\n"});
208 template <
class B
idirIt>
225 while (!(*i < *--i2))
244 std::sort(s.begin(), s.end());
248 std::cout << s <<
'\n';