//-------------------------------------------------------------------- // // Laboratory 2 ptlist.cpp // // (Partial) array implementation of the Point List ADT // //-------------------------------------------------------------------- #include #include #include "ptlist.h" using namespace std; //-------------------------------------------------------------------- PointList:: PointList () // Creates an empty list. Allocates enough memory for maxNumber // points (defaults to defMaxListSize). : size(0), cursor(-1) { } //-------------------------------------------------------------------- bool PointList:: gotoNext () // If the cursor is not at the end of a list, then moves the cursor // to the next point in the list and returns true. Otherwise, returns false. { bool result; // Result returned if ( cursor != size-1 ) { cursor++; result = true; } else result = false; return result; } //-------------------------------------------------------------------- void PointList:: showStructure () const // Outputs the points in a list. If the list is empty, outputs // "Empty list". This operation is intended for testing/debugging // purposes only. { int j; // Loop counter if ( size == 0 ) cout << "Empty list" << endl; else { cout << "size = " << size << " cursor = " << cursor << endl; // maxListSize is very large. Only output first 10 positions. if ( size > 10 ) cout << "Only printing first 10 points." << endl; for ( j = 0 ; j < 10 ; j++ ) cout << j << "\t"; cout << endl; for ( j = 0 ; j < (size>10 ? 10 : size) ; j++ ) cout << "(" << points[j].x << "," << points[j].y << ")\t"; cout << endl; } } //--------------------------------------------------------------------