예제 #1
0
    void rquicksort(linked_list<int>& ll)
    {
        cout << "rquicksort: TOP: ll = " << endl;
        ll.dump();
        int pivot = ll.get_last();
        cout << "rquicksort: pivot = " << pivot << endl;
        linked_list<int> lm;
        linked_list<int> ln;
        while (ll.get_first() != -1)
        {
            if (ll.get_first() < pivot)
            {
                lm.add_last(ll.get_first());
                ll.remove_first();
            }
            else if (ll.get_first() > pivot)
            {
                ln.add_last(ll.get_first());
                ll.remove_first();
            }
            else if (ll.get_first() == pivot)
            {
                ll.remove_first();
            }

        }
        cout << "rquicksort: lm = " << endl;
        lm.dump();
        cout << "rquicksort: ln = " << endl;
        ln.dump();

        if (lm.get_first() != lm.get_last())
        {
            cout << "calling recursively with lm..." << endl;
            rquicksort(lm);
        }
        if (ln.get_first() != ln.get_last())
        {
            cout << "calling recurisvely with ln..." << endl;
            rquicksort(ln);
        }
        cout << "rquicksort: after recursive calls, concatenating...!" << endl;
        while (lm.get_first() != -1)
        {
            cout << "adding " << lm.get_first() << " from lm" << endl;
            ll.add_last(lm.get_first());
            lm.remove_first();
        }
        ll.add_last(pivot);
        cout << "adding " << pivot << " from pivot" << endl;
        while (ln.get_first() != -1)
        {
            cout << "adding " << ln.get_first() << " from ln" << endl;
            ll.add_last(ln.get_first());
            ln.remove_first();
        }
        cout << "rquicksort: done concatenating, ll =" << endl;
        ll.dump();

    }
예제 #2
0
 T pop()
 {
     T tmp = top();
     ll.remove_first();
     return tmp;
 }