///
///
// Sort Algorithm Data Structure Compositor.h //
///
//
#include
Template
Class Compositor
{
PUBLIC:
Compositor (): sort (null) {}
Void Creat (); // Creating a rank number
Void bubble (); // bubbling sort
Void insert (); // Insert sort
// Quick sort
Void Quick ();
Void Qsort (int, int);
INT Partition (int low, int high);
// Multiple sort
Void Merge (Type SR [], Type Tr [], INT I, INT M, INT N);
Void Msort (Type Sr [], Type TR1 [], INT S, INT T);
Void mergesort ();
// Select sort
void select ();
Void print (); // Print the result
protected:
TYPE * SORT;
Int leng;
}
Template
Void Compositor
{
Cout << "Enter the number of data you need to sort:";
Cin >> Leng;
While (Leng <= 0)
{
COUT << "Enter data is incorrect";
Cin >> Leng;
}
Sort = new type [ieg];
Cout << "Please enter each data item:";
For (int i = 0; i CIN >> SORT; } Template void compositor { Creat (); TYPE TEMP; For (int i = 1; i { IF (sort { Temp = sort; For (int J = I-1; Temp { Sort [J 1] = Sort [J]; } Sort [J 1] = TEMP; } } PRINT (); } Template Void Compositor { Creat (); TYPE TEMP; For (int i = leng-1; i> = 0; I -) { For (int J = 0; j { IF (sort [j]> sort [j 1]) { Temp = sort [j]; Sort [j] = sort [j 1]; Sort [J 1] = TEMP; } } } PRINT (); } Template Void Compositor { Creat (); QSORT (0, Leng-1); PRINT (); } Template Void Compositor { IF (S { INT pivotloc = partition (s, t); Qsort (s, pivotloc-1); QSORT (Pivotloc 1, T); } } Template INT Compositor { TYPE PIVOTKEY = SORT [low]; While (low { While (low --h; Sort [low ] = sort [high]; While (low low; Sort [high -] = sort [low]; } Sort [low] = pivotkey; Return Low; } Template Void Compositor { Creat (); Msort (sort, sort, 0, leng-1); PRINT (); } Template Void Compositor { Int m; TYPE * TR2 = New Type [T-S]; IF (s == T) TR1 [S] = SR [S]; Else { m = (t s) / 2; Msort (SR, TR2, S, M); Msort (SR, TR2, M 1, T); MERGE (TR2, TR1, S, M, T); } } Template Void Compositor { For (int J = m 1, k = i; i <= m && j <= n; k ) { IF (SR <= SR [J]) Tr [k] = SR [i ]; Else Tr [K] = SR [J ]; } While (i <= m) Tr [k ] = SR [i ]; While (j <= n) Tr [K ] = SR [J ]; } Template Void Compositor { Creat (); TYPE TEMP; Int T; For (int i = 0; i { T = i; For (int J = i 1; j { IF (sort [t]> sort [j]) T = J; } IF (t! = i) { Temp = sort [t]; Sort [t] = sort; Sort = TEMP; } } PRINT (); } Template Void Compositor { COUT << "Sorting results are:"; For (int i = 0; i COUT << Sort << " Cout << Endl;