X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=gr-trellis%2Fsrc%2Flib%2Fquicksort_index.cc;h=b75896a20924862d84c995899e19676dc029dfb2;hb=ea29b08aeb54227e6628f655ccfdb96fe4d8c378;hp=fbb05d4824f2b4a3558ab8eb4073df6c2c5bbe41;hpb=18a684bf3dc144c48fc4cc6cc72f5070febd8074;p=debian%2Fgnuradio diff --git a/gr-trellis/src/lib/quicksort_index.cc b/gr-trellis/src/lib/quicksort_index.cc index fbb05d48..b75896a2 100644 --- a/gr-trellis/src/lib/quicksort_index.cc +++ b/gr-trellis/src/lib/quicksort_index.cc @@ -6,7 +6,7 @@ * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) + * the Free Software Foundation; either version 3, or (at your option) * any later version. * * GNU Radio is distributed in the hope that it will be useful, @@ -22,65 +22,47 @@ #include "quicksort_index.h" -template void SWAP (T & a, T & b) +template +void +SWAP +(T & a, T & b) { -T temp=a; -a=b; -b=temp; + T temp = a; + a = b; + b = temp; } - -template void quicksort_index(std::vector & p, std::vector & index, int left, int right) +template +void +quicksort_index +(std::vector & p, std::vector & index, int left, int right) { - -if (left < right) { + if (left < right) { int i = left; int j = right + 1; T pivot = p[left]; do { - do - i++; - while ((p[i] < pivot) && (i < right)); - do - j--; - while ((p[j] > pivot) && (j > left)); - if (i < j) { - SWAP (p[i],p[j]); - SWAP (index[i],index[j]); - } + do + i++; + while ((p[i] < pivot) && (i < right)); + do + j--; + while ((p[j] > pivot) && (j > left)); + if (i < j) { + SWAP (p[i],p[j]); + SWAP (index[i],index[j]); + } } while (i < j); SWAP (p[left], p[j]); SWAP (index[left], index[j]); quicksort_index (p,index, left, j-1); quicksort_index (p,index, j+1, right); -} -} - - - -void quicksort_index1(std::vector & p, std::vector & index, int left, int right) -{ - -if (left < right) { - int i = left; - int j = right + 1; - int pivot = p[left]; - do { - do - i++; - while ((p[i] < pivot) && (i < right)); - do - j--; - while ((p[j] > pivot) && (j > left)); - if (i < j) { - SWAP (p[i],p[j]); - SWAP (index[i],index[j]); - } - } while (i < j); - SWAP (p[left], p[j]); - SWAP (index[left], index[j]); - quicksort_index1 (p,index, left, j-1); - quicksort_index1 (p,index, j+1, right); -} + } } +// instantiate an version of the quicksort_index +//template void SWAP (int & a, int & b); +template +void +quicksort_index +(std::vector & p, std::vector & index, int left, int right);