コード例 #1
0
int main()
{
    SortedList* sl = new SortedList();

    sl->insert(1);
    sl->insert(50);

    sl->displayList();

    sl->insert(3);
    sl->insert(20);
    sl->insert(7);

    sl->displayList();
    
    while(sl->removeFirst())
	sl->displayList();
    
    delete sl;
    
    return 0;
} // end main()
int main()
{
    int j;
    time_t aTime; // seed random numbers
    srand(static_cast<unsigned>(time(&aTime)));
    const int size = 10;

    Link* linkArray[size]; // array of ptrs to links

    for(j = 0; j < size; j++) // fill with ptrs to links
    {
	int n = rand() % 99; // random number (0 to 99)
	Link* pNewLink = new Link(n);
	linkArray[j] = pNewLink;
    }

    cout << "Unsorted array: ";
    for(j = 0; j < size; j++)
	linkArray[j]->displayLink();
    cout << endl;

    SortedList *sl = new SortedList(linkArray, size);

    for(j = 0; j < size; j++)
	linkArray[j] = sl->removeFirst();

    cout << "Sorted Array: ";
    for(j = 0; j < size; j++)
	linkArray[j]->displayLink();
    cout << endl;

    for(j = 0; j < size; j++) // delete indivisual links
	delete linkArray[j];
    
    return 0;
} // end main()