0001 /****************************************************************************************** 0002 * Test of queue 0003 ******************************************************************************************/ 0004 #include "queue_test.h" 0005 0006 int testID = 0; //测试编号 0007 0008 /****************************************************************************************** 0009 * 测试栈 0010 ******************************************************************************************/ 0011 template <typename T> void testQueue ( Rank n ) { 0012 Queue<T> Q; 0013 printf ( "\n ==== Test %2d. Growing queue\n", testID++ ); 0014 while ( Q.size() < n ) { 0015 ( Q.empty() || ( 30 < dice ( 100 ) ) ) ? 0016 Q.enqueue ( (T) dice ( 2 * n ) ) : //70%入队 0017 Q.dequeue(); //30%出队 0018 print ( Q ); 0019 } 0020 printf ( "\n ==== Test %2d. Shrinking queue\n", testID++ ); 0021 while ( !Q.empty() ) { 0022 ( 70 < dice ( 100 ) ) ? 0023 Q.enqueue ( (T) dice ( 2 * n ) ) : //30%入队 0024 Q.dequeue(); //70%出队 0025 print ( Q ); 0026 } 0027 } 0028 0029 /****************************************************************************************** 0030 * 测试队列 0031 ******************************************************************************************/ 0032 int main ( int argc, char* argv[] ) { 0033 if ( 2 > argc ) { printf ( "Usage: %s <size of test>\a\a\n", argv[0] ); return 1; } 0034 srand((unsigned int)time(NULL)); //随机种子 0035 //srand( 31415926 ); //固定种子(假种子,调试用) 0036 testQueue<int> ( atoi ( argv[1] ) ); //元素类型可以在这里任意选择 0037 return 0; 0038 }