// Test program for double-ended queues. // To compile: // CC -O5 assign1.cpp Exception.cpp -o assign1 #include "DoubleEnded.h" #include const int N = 1787; const int M = 2357; int main( ) { DoubleEnded Q; int MinVal1, MinVal2, MaxVal1, MaxVal2; int i, j; for( i = N; i != 0; i = ( i + N ) % M ) Q.Insert( i ); cout << "Completed first round of insertions" << endl; for( j = 1; !Q.IsEmpty( ); j += 2 ) { MinVal1 = Q.FindMin( ); Q.DeleteMin( ); Q.DeleteMin( MinVal2 ); if( MinVal1 != j || MinVal2 != j+1 ) cout << "OOPS!!!!!" << MinVal1 << " " << MinVal2 << " " << j << " " << (j+1) << endl; MaxVal1 = Q.FindMax( ); Q.DeleteMax( ); Q.DeleteMax( MaxVal2 ); if( MaxVal1 != M - j || MaxVal2 != M - j - 1 ) cout << "OOPS!!!!!" << MaxVal1 << " " << MaxVal2 << " " << (M-j) << " " << (M-j-1) << endl; } cout << "Completed first round of deletions" << endl; for( i = N; i != 0; i = ( i + N ) % M ) Q.Insert( i ); cout << "Completed second round of insertions" << endl; for( i = 0; i < M - 5; i += 2 ) { Q.DeleteMin( ); Q.DeleteMax( ); } for( ; !Q.IsEmpty( ); Q.DeleteMin( ), Q.DeleteMax( ) ) cout << Q.FindMin( ) << endl << Q.FindMax( ) << endl; cout << "Program end reached" << endl; return 0; }