Annotation of researchv10no/cmd/cfront/libstring/test4.c, revision 1.1

1.1     ! root        1: /* sort standard input and print unique Strings */
        !             2: 
        !             3: #include "String.h"
        !             4: #include "list.h"
        !             5: 
        !             6: listdeclare(String)
        !             7: 
        !             8: main()
        !             9: {
        !            10:        String  s;
        !            11:        String_list     myList;
        !            12:        /* input */
        !            13:        while (cin >> s)
        !            14:                myList.put(s);
        !            15:        /* (bubble) sort */
        !            16:        int     swapFlag;
        !            17:        int     loopCount = 0, swapCount = 0;
        !            18:        if ( myList )
        !            19:                do {
        !            20:                        swapFlag = FALSE;
        !            21:                        String_list_iterator    it(myList);
        !            22:                        String  x;
        !            23:                        String  y;
        !            24:                        while ( it.nextX(x) && it.peekX(y) ) {
        !            25:                                loopCount++;
        !            26:                                if ( x > y ) {
        !            27:                                        it.replace(y);
        !            28:                                        it.r_replace(x);
        !            29:                                        swapFlag = TRUE;
        !            30:                                        swapCount++;
        !            31:                                } else if ( x == y )
        !            32:                                        it.remove();
        !            33:                        }
        !            34:                } while ( swapFlag );
        !            35:        /* print result */
        !            36:        cout << myList;
        !            37:        cout << "\nloopCount = " << loopCount << ", swapCount = " << swapCount << "\n";
        !            38: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.