SOL9 2.0 Sample: QuickSort

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * QuickSort.cpp 
 * Copyright (c) 2009 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL++2000
// 2000.02.18

#include <sol\ApplicationView.h>
#include <sol\Stdio.h>
#include <sol\QuickSorter.h>
#include <sol\ScrolledText.h>
#include <sol\String.h>
#include <sol/StringConverter.h>
#include <sol/StringT.h>

namespace SOL {

class AppView :public ApplicationView {
private:
    ScrolledText text;

public:
    /**
     * Constructor
     */
    AppView(Application& applet, const TCHAR* label, Args& args)
        :ApplicationView(applet, label, args)
    {
        Args ar;
        text.create(this, NULL, ar);
        add(text);

        // Add an eventhandler start to handle a user-defined event.
        addEventHandler(WM_USER+300, this, 
            (Handler)&AppView::start, null);

        // Post the user-defined event.
        post(WM_USER+300, 0, 0);
    }

private:
    long start(Event& event) 
    {
        static    int integers[] = {
            1, 200, 3, 11, 0,
            500, 20, 600, 30
        };

        static wchar_t* strings[] = {
            L"orange", L"banana",  L"apple", L"melon", L"grape",
        };

        static char* cstrings[] = {
            "USA", "Russia", "China", "Taiwan", "England",
            "Japan", "France", "Germany",
        };

        QuickSorter qsorter1;
        // Sort an array of integers.
        qsorter1.sort(integers, XtNumber(integers));
        qsorter1.wait();

        // Sort an array of TCHAR*.
        QuickSorter    qsorter2;
        qsorter2.sort(strings,  XtNumber(strings));
        qsorter2.wait();

        static Object* objects[10];
        int num = 0;
        objects[num++] = new String("dog");
        objects[num++] = new String("sheep");
        objects[num++] = new String("pig");
        objects[num++] = new String("cat");
        objects[num++] = new String("hen");
        objects[num++] = new String("ox");

        // Sort an array of instances of String.
        QuickSorter qsorter3;
        qsorter3.sort(objects, num);
        qsorter3.wait();

        // Sort an array of instances of String.
        QuickSorter qsorter4;
        qsorter4.sort(cstrings, XtNumber(cstrings));
        qsorter4.wait();

        int i = 0;
        for (i = 0; i<XtNumber(integers); i++) {
                text.printf(_T("%d \r\n"), integers[i]);
        }

        text.printf(_T("--------------------\r\n"));

        for (i = 0; i<XtNumber(strings); i++) {
            text.printf(_T("%s \r\n"), strings[i]);
        }
    
        text.printf(_T("--------------------\r\n"));

        for (i = 0; i<num; i++) {
            String* string = (String*)objects[i];
            text.printf(_T("%s \r\n"), (const TCHAR*)(*string));
        }

        text.printf(_T("--------------------\r\n"));

        for (i = 0; i<XtNumber(cstrings); i++) {
            StringConverter converter;
            StringT<TCHAR> tstring;
            converter.convert(cstrings[i], tstring);
            text.printf(_T("%s \r\n"), (const TCHAR*)tstring);
        }

        return 0L;
    }
};

}

//
void Main(int argc, TCHAR** argv)
{
    const TCHAR* appClass = _T("QuickSort");
    try {
        Application applet(appClass, argc, argv);

        Args  args;
        AppView appView(applet, appClass, args);
        appView.realize(); 

        applet.run();
    } catch (...) {

    }
}

Last modified: 11 Nov 2009

Copyright (c) 2009 Antillia.com ALL RIGHTS RESERVED.