int main()
{
    std::vector<int> v1 { 1, -8, 4, 48, -10, 700, 5, -7, 54545, -777 };

    QuickSort<decltype(v1)> qs;
    qs.sort(v1);

    for (auto const & element : v1)
    {
        std::cout << element << std::endl;
    }

    return 0;
}
Example #2
0
int main(int argc, const char * argv[]) {
    
    int array[] = {3,4,5,2,1,0,22,33,12,-20,45,333,87,8};
    int len = sizeof(array) / sizeof(*array);
    
    vector<int> dat(array, array+len);
    
    QuickSort qs;
//    qs.setData(array, len);
    qs.setData(dat);
    
    qs.sort();
    
    return 0;
}
int main(int argc, char** argv)
#endif
{
    HashTableST<std::string, int> myHahTableST;
    myHahTableST.put("Skornyakov", 2);
    myHahTableST.put("Skornyakov", 3);
    myHahTableST.put("Abramov", 3);
    myHahTableST.put("Losev", 4);
    myHahTableST.put("Utin", 5);

    int val = 0;
    val = myHahTableST.get("Utin");
    myHahTableST.remove("Skornyakov");



    RBTreeST<std::string, int> phoneNumbers;
    phoneNumbers.put("Skornyakov", 2);
    phoneNumbers.put("Abramov", 3);
    phoneNumbers.put("Losev", 4);
    phoneNumbers.put("Utin", 5);

    bool test = phoneNumbers.contains("Pukin");
    test = phoneNumbers.contains("Utin");


    while(1) {
        MaxPQ<int> maxPQ;

        srand((unsigned int)time(NULL));
        int arr[1000];
        for(int i = 0; i < 1000; i++) {
            arr[i]=rand();
        }

        /*
        heapsort<int>(arr, 1000);

        for(int i = 0; i < 10000; i++){
            maxPQ.insert(rand());
        }

        for(int i = 0; i < 10000; i++){
            int k;
            while(maxPQ.delMax(&k)){
                cout << k << " ";
            }
        }
        cout << endl;*/

        BinTreeST<string, int> binTreeST;
        binTreeST.put("Skornyakov", 14);
        binTreeST.put("Abramov", 12);
        binTreeST.put("Aaskold", 12);
        binTreeST.put("Antonov", 12);
        binTreeST.put("Ivanov", 12);
        binTreeST.put("Sidorov", 13);
        binTreeST.put("Nesterov", 11);
        binTreeST.put("Nesterenko", 11);
        binTreeST.put("Kolcov", 11);
        int bstSize = binTreeST.size();
        binTreeST.remove("Abramov");
        bstSize = binTreeST.size();
        binTreeST.remove("Skornyakov");
        bstSize = binTreeST.size();
        binTreeST.remove("Aaskold");
        bstSize = binTreeST.size();

        /*
        for(int i = 0; i < 1000; i++){
            string newStr;
            newStr.insert(newStr.end(), (char)(rand()%93+33));
            newStr.insert(newStr.end(), (char)(rand()%93+33));
            newStr.insert(newStr.end(), (char)(rand()%93+33));
            binTreeST.put(newStr, rand()%101);
        }*/


        int val = binTreeST.get("Skornyakov");
        std::string searchitem("Azotov");
        string floorVal = binTreeST.floor(searchitem);
        string ceilingVal = binTreeST.ceiling(searchitem);
        std::cout << "floor(" << searchitem <<") = " << floorVal << endl;
        std::cout << "ceiling(" << searchitem <<") = " << ceilingVal << endl;
        std::cout << "rank(" << searchitem <<") = " << binTreeST.rank(searchitem) << endl;



        BinSearchST<string, int> binarySearchST;
        binarySearchST.put("���������", 14);
        binarySearchST.put("���������", 12);
        binarySearchST.put("�������", 13);
        binarySearchST.put("����a", 11);
        binarySearchST.put("���������", 11);
        binarySearchST.put("���������a", 11);
        binarySearchST.remove("���������a");


        for(int i = 0; i < 1000; i++) {
            string newStr;
            newStr.insert(newStr.end(), (char)(rand()%93+33));
            newStr.insert(newStr.end(), (char)(rand()%93+33));
            newStr.insert(newStr.end(), (char)(rand()%93+33));
            binarySearchST.put(newStr, rand()%101);
        }

        val = binarySearchST.get("���������");
        val = binarySearchST.get("���������");
        val = binarySearchST.get("���������a");
        val = binarySearchST.get("���������");

        vector<int> intVec;

        for(int i = 0; i < 1000000; i++) {
            intVec.push_back(rand()) ;
        }

        // Quicksort
        cout << "Quicksort:" << endl;
        QuickSort<int> intQuicksort;
        Mergesort<int> intMergeSort;

        time_t before, after;
        time(&before);

        //qsort(&intVec[0], intVec.size(), sizeof(int), compare);
        intQuicksort.sort(intVec);
        //std::sort(intVec.begin(), intVec.end());
        //intMergeSort.sort(intVec);
        time(&after);
        double sec = difftime(after, before);

        if(intQuicksort.isSorted(intVec))
            cout << "Sorted";
        else
            cout << "Not sorted";

        cout << endl;
    }
    /*
    // Mergesort
    cout << "Mergesort" << endl;
    Mergesort<int> intMergeSort;
    //intMergeSort.sort(intVec);
    intMergeSort.bottomUpSort(intVec);

    for(std::vector<int>::iterator it = intVec.begin(); it != intVec.end(); ++it){
    cout << *it << " ";
    }
    cout << endl;
    */
    /*
    // Shellsort
    cout << "Shellsort" << endl;
    Shell<int> intShellSort;
    intShellSort.sort(intVec);

    for(std::vector<int>::iterator it = intVec.begin(); it != intVec.end(); ++it){
    cout << *it << " ";
    }
    cout << endl;
    */

    /*
    // Insertion sort
    cout << "Insertion sort: " << endl;
    Insertion<int> intInsertion;

    intInsertion.sort(intVec, 0, 20);
    for(std::vector<int>::iterator it = intVec.begin(); it != intVec.end(); ++it){
    cout << *it << " ";
    }
    cout << endl;*/

    /*
    // Selection sort
    cout << "Selection sort: " << endl;
    Selection<int> intSelection;
    intSelection.sort(intVec);

    for(std::vector<int>::iterator it = intVec.begin(); it != intVec.end(); ++it){
    cout << *it << " ";
    }
    cout << endl;
    */

    // array Q implementation
    array_impl_q::Queue<int> arrayQ;
    int itemsCount = 100;
    cout << "Enqueue " << itemsCount << " items" << endl;
    for (int i = 0; i < itemsCount; i++) {
        arrayQ.enqueue(i);
    }

    itemsCount = 90;
    cout << "Dequeue " << itemsCount << " items" << endl;
    try {
        for (int i = 0; i < itemsCount; i++) {
            cout << arrayQ.dequeue() << " ";
        }
        cout << endl;
    }
    catch(const char *str) {
        cout << endl << str << endl;
    }
    catch(...) {
        cout << endl << "Unknown exception" << endl;
    }


    /*
    // linked list Q implementation
    linklist_q::Queue<int> linkedListQ;
    unsigned int itemsCount = 1500000;
    cout << "Enqueue " << itemsCount << " items" << endl;
    for (int i = 0; i < itemsCount; i++) {
    linkedListQ.enqueue(i);
    }
    itemsCount = 1500000;
    cout << "Dequeue " << itemsCount << " items" << endl;
    try{
    for (int i = 0; i < itemsCount; i++) {
    cout << linkedListQ.dequeue() << " ";
    }
    cout << endl;
    }
    catch(const char *str){
    cout << endl << str << endl;
    }
    catch(...){
    cout << endl << "Unknown exception" << endl;
    }
    */




    /*
    // linked list implementation stack
    cout << "****Stack linked list implementation****" << endl;
    cout << "stack push(1-100)" << endl;
    linked_list_stack::Stack<int> integerStack;
    for (int i = 0; i < 100000; i++) {
    integerStack.push(i);
    }
    try {
    cout << "stack pop(105)" << endl;
    for (int i = 0; i < 105000; i++) {
    cout << integerStack.pop() << " ";
    }
    } catch (const char *p) {
    cout << endl << p << endl;
    } catch (...) {
    cout << "Unknown exception" << endl;
    }

    cout << endl;
    cout << "stack push(1-100)" << endl;
    for (int i = 0; i < 100; i++) {
    integerStack.push(i);
    }
    cout << "stack pop all" << endl;
    while (!integerStack.isEmpty()) {
    cout << integerStack.pop() << " ";
    }

    cout << endl;

    // array implementation stack
    cout << "****Stack resizing array implementation****" << endl;
    cout << "stack push(1-100)" << endl;
    array_impl_stack::Stack<int> integerArrayBasedStack;
    for (int i = 0; i < 100; i++) {
    integerArrayBasedStack.push(i);
    }

    try {
    cout << "stack pop(105)" << endl;
    for (int i = 0; i < 105; i++) {
    cout << integerArrayBasedStack.pop() << " ";
    }
    } catch (const char *p) {
    cout << endl << p << endl;
    } catch (...) {
    cout << "Unknown exception" << endl;
    }

    cout << "stack push(1-100)" << endl;
    for (int i = 0; i < 100; i++) {
    integerArrayBasedStack.push(i);
    }
    cout << "stack pop all" << endl;
    try {
    while (!integerArrayBasedStack.isEmpty()) {
    cout << integerArrayBasedStack.pop() << " ";
    }
    } catch (const char* p) {
    cout << endl << p << endl;
    } catch (...) {
    cout << endl << "Unknown exception" << endl;
    }
    cout << endl;*/

    return 0;
}