13791 - EE2310_Lab_14_1   

Description

Generic MergeSort

You are going to re-implement Lab 9's MergeSort() function using function templates. Your MergeSort() should work on all types with < and <= overloaded. We will test your MergeSort() with Card type from Lec 8-1. Re-implement Card as a class with the following member functions so that it will work with our given main(): < , <= , << , >>, and (possibly) constructors. You should use the following macro so that your output will show the suit symbols.

#if defined(_WIN32) || defined(__MSDOS__)
   #define SPADE   "\x06"
   #define CLUB    "\x05"
   #define HEART   "\x03"
   #define DIAMOND "\x04"
#else
   #define SPADE   "\xE2\x99\xA0"
   #define CLUB    "\xE2\x99\xA3"
   #define HEART   "\xE2\x99\xA5"
   #define DIAMOND "\xE2\x99\xA6"
#endif

If you include the above macro, then you can show a spade symbol by adding

cout << SPADE;

main() is given. Do no make any changes, otherwise you may get penalty points.

int main(){
    int size;
    cin >> size;
    Card *a = new Card[size];
    for(int i=0; i< size; i++) {
        cin >> a[i];
    }

    //  sort
    MergeSort<Card>(a, 0, size-1);

    //  output
    for(int i=0; i< size-1; i++) {
        cout << a[i] << ' ';
    }

    cout << a[size - 1] << endl;
    return 0;
}

Input

7
S2 CT HA SK H3 D5 CQ

Output

♠2 ♥3 ♦5 ♣10 ♣Q ♠K ♥A

Sample Input  Download

Sample Output  Download

Tags




Discuss