You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
5 years ago
|
TestCursorList.cpp - Test program for cursor implementation of linked lists
|
||
|
|
||
|
#include <iostream.h>
|
||
|
#include "CursorList.h"
|
||
|
|
||
|
// Simple print method
|
||
|
template <class Object>
|
||
|
void printList( const List<Object> & theList )
|
||
|
{
|
||
|
if( theList.isEmpty( ) )
|
||
|
cout << "Empty list" << endl;
|
||
|
else
|
||
|
{
|
||
|
ListItr<Object> itr = theList.first( );
|
||
|
for( ; !itr.isPastEnd( ); itr.advance( ) )
|
||
|
cout << itr.retrieve( ) << " ";
|
||
|
}
|
||
|
|
||
|
cout << endl;
|
||
|
}
|
||
|
|
||
|
vector<List<int>::CursorNode> List<int>::cursorSpace;
|
||
|
|
||
|
int main( )
|
||
|
{
|
||
|
List<int> theList;
|
||
|
ListItr<int> theItr = theList.zeroth( );
|
||
|
int i;
|
||
|
|
||
|
printList( theList );
|
||
|
|
||
|
for( i = 0; i < 10; i++ )
|
||
|
{
|
||
|
theList.insert( i, theItr );
|
||
|
printList( theList );
|
||
|
theItr.advance( );
|
||
|
}
|
||
|
|
||
|
for( i = 0; i < 10; i += 2 )
|
||
|
theList.remove( i );
|
||
|
|
||
|
for( i = 0; i < 10; i++ )
|
||
|
if( ( i % 2 == 0 ) != ( theList.find( i ).isPastEnd( ) ) )
|
||
|
cout << "Find fails!" << endl;
|
||
|
|
||
|
cout << "Finished deletions" << endl;
|
||
|
printList( theList );
|
||
|
|
||
|
return 0;
|
||
|
}
|