0001 /****************************************************************************************** 0002 * Test of Vector 0003 ******************************************************************************************/ 0004 #include "cursor_list.h" 0005 0006 int testCursor(Rank testSize) { //测试游标式列表 0007 CursorList<char> CL(testSize); CL.print(); 0008 //CL.insert('A'); CL.insert('B'); CL.insert('C'); CL.insert('D'); CL.insert('E'); CL.print(); 0009 //CL.remove(CL.find('A')); CL.remove(CL.find('B')); CL.remove(CL.find('C')); CL.remove(CL.find('D')); CL.remove(CL.find('E')); CL.print(); 0010 //CL.insert('A'); CL.insert('B'); CL.insert('C'); CL.insert('D'); CL.insert('E'); CL.print(); 0011 for (Rank i = 0; i < 2*testSize; i++) { 0012 char x = 'A' + (rand() % 26); 0013 if (30 < (rand() % 100)) { 0014 Rank r = CL.insert(x); 0015 if (r < testSize) 0016 printf("%c inserted at %d\n", x, r); 0017 else 0018 printf("failed to insert %c into full CL\n", x); 0019 } else { 0020 if (testSize == CL.find(x)) 0021 printf("%c not found\n", x); 0022 else 0023 printf("%c removed at %d\n", x, CL.remove(CL.find(x))); 0024 } 0025 CL.print(); 0026 } 0027 for (char x = 'A'; x <= 'Z'; x++) { 0028 while (testSize != CL.find(x)) 0029 printf("%c removed at %d\n", x, CL.remove(CL.find(x))); 0030 CL.print(); 0031 } 0032 return 0; 0033 } 0034 0035 int main(int argc, char* argv[]) { 0036 if (2 > argc) { printf("Usage: %s <size of test>\a\a\n", argv[0]); return 1; } 0037 srand(31415926); //srand((uint32_t) time(nullptr)); //随机种子 0038 testCursor(atoi(argv[1])); //元素类型可以在这里任意选择 0039 return 0; 0040 }