0 recommended
# I nclude "iostream"
# I nclude "vector"
# I nclude "fstream"
Using namespace STD;
Const int max = 100;
// Quick Sort Template
Template <class elemtype>
Class quick_sort {
Public:
Int partition (INT low, int high );
Void recquick_sort (INT frist, int last );
Quick_sort (vector <elemtype> & S );
~ Quick_sort ();
Protected:
Vector <elemtype> L;
};
Template <class elemtype>
Quick_sort <elemtype >:: quick_sort (vector <elemtype> & S)
{
L = s;
Recquick_sort (0, L. Size ()-1 );
For (vector <int >:: iterator iter = L. Begin (); iter! = L. End (); ITER ++)
Cout <* ITER <"";
Cout <Endl;
}
Template <class elemtype>
Quick_sort <elemtype> ::~ Quick_sort (){
}
Template <class elemtype>
Void quick_sort <elemtype>: recquick_sort (INT first, int last)
{
Int poiv;
If (first <last)
{
Poiv = partition (first, last );
Recquick_sort (first, poiv-1 );
Recquick_sort (poiv + 1, last );
}
}
Template <class elemtype>
Int quick_sort <elemtype >:: partition (INT low, int high)
{
Elemtype poiv;
Poiv = L [low];
While (low {
While (low <High & L [High]> = poiv) -- high;
L [low] = L [High];
While (low <High & L [low] <= poiv) ++ low;
L [High] = L [low];
}
L [low] = poiv;
Return low;
}
Int main ()
{
Int I, n, E;
Vector <int> L;
Ifstream in;
In. Open ("in.txt ");
If (! In)
{
Cerr <"error: Unable to open the file:" <in <Endl;
Return-1;
}
While (in> N)
{
For (I = 0; I <n; I ++)
{
In> E;
L. push_back (E );
}
Quick_sort <int> q (L );
L. Resize (0 );
}
Return 0;
}