



































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




































































// SPECIFICATION FILE ( unsorted.h ) #include “ItemType.h”
class UnsortedType // declares a class data type { public : // 8 public member functions void UnsortedType ( ); bool IsFull ( ) const; int GetLength ( ) const ; // returns length of list ItemType GetItem ( ItemType item, bool& found); void PutItem ( ItemType item ); void DeleteItem ( ItemType item ); void ResetList ( ); ItemType GetNextItem ();
private : // 3 private data members int length; ItemType info[MAX_ITEMS]; int currentPos; };
[ 1 ] [ 2 ]
[MAX_ITEMS-1]
[MAX_ITEMS-1]
[MAX_ITEMS-1]
19
ItemType UnsortedType::GetItem ( ItemType item, bool& found ) // Pre: Key member of item is initialized. // Post: If found, item ’ s key matches an element ’ s key in the list // and a copy of that element is returned; // otherwise, input item is returned. { bool moreToSearch; int location = 0;
found = false; moreToSearch = ( location < length ); while ( moreToSearch && !found ) { switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++; moreToSearch = ( location < length ); break; case EQUAL : found = true; item = info[ location ]; break; } } return item; } (^) Docsity.com 19
[MAX_ITEMS-1]