restructure and add ipi texs

This commit is contained in:
2019-11-06 18:24:04 +01:00
parent e21da561fc
commit 8fd8d2a485
155 changed files with 129 additions and 0 deletions
@@ -0,0 +1,25 @@
template <class C>
inline void reheap (C& a, int n, int i) {
while (2*i+1<n)
{
int l = 2*i+1;
int r = l+1;
int k = ((r<n) && (a[r]>a[l])) ? r : l;
if (a[k]<=a[i]) break;
std::swap(a[k], a[i]);
i = k;
}
}
template <class C>
void heapsort (C& a)
{
// build the heap by reheaping from the rear
for (int i=a.size()-1; i>=0; i--)
reheap(a, a.size(), i);
// build the sorted list by popping the heap
for (int i=a.size()-1; i>=0; i--) {
std::swap(a[0],a[i]);
reheap(a, i, 0);
}
}