00001 #include <j2k/Fred/Standard.hpp>
00002
00003 #define Elem long
00004
00005 #include <j2k/DataType/Link/DLink.cpp>
00006 #include <j2k/DataType/Link/DList.cpp>
00007
00008 #define List DList
00009
00010 void test()
00011 {
00012 List L1;
00013 List L2;
00014 List L3;
00015
00016 L2.append(10);
00017
00018 L2.display();
00019
00020 L2.insert(20);
00021 L2.prev();
00022 L2.append(15);
00023
00024 L2.display();
00025
00026 L1.setFirst();
00027 L1.display();
00028 L1.insert( 39 );
00029 L1.next();
00030 L1.insert(12);
00031 L1.append(5);
00032 L1.prev();
00033 L1.insert(4);
00034 L1.display();
00035 L1.append(3);
00036 L1.append(2);
00037 L1.append(1);
00038 L1.display();
00039
00040 L2.setFirst();
00041 L2.find(20);
00042
00043 if ( L2.isInList() )
00044 {
00045 printf( "L2 curr: \t" );
00046 printf( "%d\n", L2.currValue() );
00047 }
00048 else
00049 {
00050 printf( "Odd - what happened to 20?\n" );
00051 }
00052
00053 printf( "L1: \n" );
00054 L1.display();
00055
00056 printf( "Size: %d \nL2:\n", L2.length() );
00057 L2.display();
00058
00059 printf( "L3: \n" );
00060 L3.display();
00061
00062 L1.setFirst();
00063 printf( "L1: \n" );
00064 L1.display();
00065
00066 if ( L1.find(20) > 0 )
00067 {
00068 printf( "Odd - shouldn't find 20 in L1!\n" );
00069 }
00070 else
00071 {
00072 printf( "20 not in L1.\n" );
00073 }
00074
00075 L1.setFirst();
00076 printf( "L1: \n" );
00077 L1.display();
00078
00079 if ( L1.find(5) > 0 )
00080 {
00081 printf( "%d @ %d\n", L1.currValue(), L1.getPos() );
00082 }
00083
00084 L2.setFirst();
00085 printf( "L2: \n" );
00086 L2.display();
00087
00088 if( L2.find(20) > 0 )
00089 {
00090 printf( "%d @ %d\n", L2.currValue(), L2.getPos() );
00091 }
00092 else
00093 {
00094 printf( "Didn't find it the first time\n" );
00095 }
00096
00097 L2.next();
00098
00099 if ( L2.find(20) > 0 )
00100 {
00101 printf( "Error: Found it again!\n" );
00102 printf( "%d @ %d\n", L2.currValue(), L2.getPos() );
00103 }
00104 else
00105 {
00106 printf( "Only once in list.\n" );
00107 }
00108
00109 L1.setFirst();
00110 printf( "L1: \n" );
00111 L1.display();
00112 printf( "%d @ %d\n", L1.currValue(), L1.getPos() );
00113
00114 L1.setValue(42);
00115
00116 printf( "L1: \n" );
00117 L1.display();
00118
00119 L2.setFirst();
00120 printf( "L2: \n" );
00121 L2.display();
00122
00123 printf( "\nRemoving: " );
00124 printf( "%d @ %d\n", L2.currValue(), L2.getPos() );
00125 printf( "%d\n", L2.remove() );
00126 printf( "%d @ %d\n", L2.currValue(), L2.getPos() );
00127
00128 printf( "L2: \n" );
00129 L2.display();
00130
00131 printf( "\nRemoving: " );
00132 printf( "%d @ %d\n", L2.currValue(), L2.getPos() );
00133 printf( "%d\n", L2.remove() );
00134 printf( "%d @ %d\n", L2.currValue(), L2.getPos() );
00135
00136 printf( "L2: \n" );
00137 L2.display();
00138
00139 printf( "Size: %d \n", L2.length() );
00140 L2.clear();
00141 printf( "L2: \n" );
00142 L2.display();
00143
00144 printf( "Size: %d \n", L2.length() );
00145 L2.append(5);
00146 printf( "L2: \n" );
00147 L2.display();
00148
00149 printf( "Start a new round.\n" );
00150 L2.clear();
00151
00152 printf( "L2: \n" );
00153 L2.display();
00154
00155 L2.setFirst();
00156 L2.insert(1);
00157
00158 printf( "L2: \n" );
00159 L2.display();
00160
00161 L2.insert(2);
00162
00163 printf( "L2: \n" );
00164 L2.display();
00165
00166 L2.setPos(2);
00167 L2.insert(3);
00168
00169 printf( "L2: \n" );
00170 L2.display();
00171
00172 printf( "That is all.\n" );
00173 printf( "-----------------------\n" );
00174 }
00175
00176 int main()
00177 {
00178 test();
00179 return 0;
00180 }