------------------------------------------------------------------------------
MC logo
Linked List Driver
[^] CSc 220 Home
------------------------------------------------------------------------------
[Introduction] [Boolean and Control] [Functions] [Arrays and Pointers] [Dynamic Arrays] [Array Errors] [Command Array] [Standard Containers] [Structs and Classes] [Automatic Pointer] [Multi-File Programs] [Copying Objects] [Templates] [Inheritance] [Plain C I/O] [Type Odds And Ends] [Plain C Strings] [File I/O]
[Bounded Safe Array] [Bounded Safe Array Driver] [PrintMe Class] [PrintMe2 Class] [PrintMeLots Class] [PrintMeLots2 Class] [PrintMe Test Driver] [Linked List Node Classes] [Linked List Classes] [Linked List Implementation] [Linked List Driver] [Expression Calculator]
linkedtest.cc
#include <iostream>
#include <fstream>
#include "linkedlist.h"

// Switch convenience
#define when break;case
#define otw break;default

/*
 * Basic testing for a linked list.
 */
void listestA(OneWayList &list)
{
        OneWayIter i(list);

        ++i;
        ++i;
        cout << i.Val() << "\n" << list;
        while(!i.End()) ++i;
        cout << " " << i.Val() << endl;

        i.Rewind();
        ++i;++i;
        (++i).Val(-44);
        i.Rewind();
        while(1)
        {
                cout << (++i).Val() << " ";
                if(i.End()) break;
        }
        cout << "\n\n";
}
/*
 * Some additional testing for a double linked list.
 */
void listestB(TwoWayList &list)
{
        TwoWayIter i(list);

        ++i; ++i;
        cout << i.Val();
        --i;
        cout << " " << i.Val() << "\n" << list << "\n";
        while(!i.End()) ++i;
        while(!i.Start())
        {
                cout << i--.Val() << " ";
        }
        cout << "\n\n";
}

main()
{
        // Input the single and double linked list, and run them.
        OneWayList sl;
        OneWayIter sli(sl);
        sli << 15 << 23 << 90 << -13 << 5 << -6 << 2 << -44 << 18;
        cout << sl << endl;
        sli.Rewind();
        sli.Add(456); sli++;
        ++sli; ++sli; ++sli;
        sli.Add(-666);
        sli++;
        while(!sli.End()) ++sli;
        sli.Add(59);
        cout << sl << endl;
        listestA(sl);

        TwoWayList dl;
        TwoWayIter dli(dl);
        dli << 48 << -6 << -5 << 2 << 218 << 34 << -5 << -98 << 417 << 3;
        cout << dl << " " << dli.Val();
        --dli; --dli;
        cout << " " << dli.Val() << endl;       
        dli.Add(516)++;
        --dli; --dli; --dli;
        dli.Add(67)++;
        ++dli; 
        cout << dli.Val() << " ";
        while(!dli.Start()) --dli;
        dli.Add(952)++;
        cout << dl << endl;
        listestA(dl);
        listestB(dl);
}