00001
00002
00003
00004
00005
00006
00007
00008 #include <utility/ostream.h>
00009 #include <utility/queue.h>
00010
00011 __USING_SYS;
00012
00013 struct Integer1 {
00014 Integer1(int _i) : i(_i), e(this) {}
00015
00016 int i;
00017 Queue<Integer1>::Element e;
00018 };
00019
00020 struct Integer2 {
00021 Integer2(int _i) : i(_i), e(this) {}
00022
00023 int i;
00024 Ordered_Queue<Integer2>::Element e;
00025 };
00026
00027 struct Integer3 {
00028 Integer3(int _i) : i(_i), e(this) {}
00029
00030 int i;
00031 Relative_Queue<Integer3>::Element e;
00032 };
00033
00034 int main()
00035 {
00036 OStream cout;
00037
00038 cout << "Queue Utility Test\n";
00039
00040 Integer1 i1(1), i2(2), i3(3), i4(4);
00041 Integer2 j1(1), j2(2), j3(3), j4(4);
00042 Integer3 k1(1), k2(2), k3(3), k4(4);
00043
00044 cout << "This is an integer queue:\n";
00045 Queue<Integer1> q1;
00046 cout << "Inserting the integer " << i1.i << " into the queue.\n";
00047 q1.insert(&i1.e);
00048 cout << "Inserting the integer " << i2.i << " into the queue.\n";
00049 q1.insert(&i2.e);
00050 cout << "Inserting the integer " << i3.i << " into the queue.\n";
00051 q1.insert(&i3.e);
00052 cout << "Inserting the integer " << i4.i << " into the queue.\n";
00053 q1.insert(&i4.e);
00054 cout << "The queue has now " << q1.size() << " elements.\n";
00055 cout << "Removing the element whose value is " << i2.i << "("
00056 << q1.remove(&i2)->object()->i << ")" << " from the queue.\n";
00057 cout << "Removing the queue's head (" << q1.remove()->object()->i
00058 << ")" << " from the queue.\n";
00059 cout << "Removing the element whose value is " << i4.i << "("
00060 << q1.remove(&i4)->object()->i << ")" << " from the queue.\n";
00061 cout << "Removing the queue's head (" << q1.remove()->object()->i
00062 << ")" << " from the queue.\n";
00063 cout << "The queue has now " << q1.size() << " elements.\n";
00064
00065 cout << "This is an ordered integer queue:\n";
00066 Ordered_Queue<Integer2> q2;
00067 cout << "Inserting the integer " << j1.i
00068 << " into the queue with order 2.\n";
00069 q2.insert(&j1.e, 2);
00070 cout << "Inserting the integer " << j2.i
00071 << " into the queue with order 3.\n";
00072 q2.insert(&j2.e, 3);
00073 cout << "Inserting the integer " << j3.i
00074 << " into the queue with order 4.\n";
00075 q2.insert(&j3.e, 4);
00076 cout << "Inserting the integer " << j4.i
00077 << " into the queue with order 1.\n";
00078 q2.insert(&j4.e, 1);
00079 cout << "The queue has now " << q2.size() << " elements.\n";
00080 cout << "Removing the element whose value is " << j2.i << "("
00081 << q2.remove(&j2)->object()->i << ")" << " from the queue.\n";
00082 cout << "Removing the queue's head (" << q2.remove()->object()->i
00083 << ")" << " from the queue.\n";
00084 cout << "Removing the queue's head (" << q2.remove()->object()->i
00085 << ")" << " from the queue.\n";
00086 cout << "Removing the queue's head (" << q2.remove()->object()->i
00087 << ")" << " from the queue.\n";
00088 cout << "The queue has now " << q2.size() << " elements.\n";
00089
00090 cout << "This is an integer queue with relative ordering:\n";
00091 Relative_Queue<Integer3> q3;
00092 cout << "Inserting the integer " << j1.i
00093 << " into the queue with relative order 2.\n";
00094 q3.insert(&k1.e, 2);
00095 cout << "Inserting the integer " << j2.i
00096 << " into the queue with relative order 3.\n";
00097 q3.insert(&k2.e, 3);
00098 cout << "Inserting the integer " << j3.i
00099 << " into the queue with relative order 4.\n";
00100 q3.insert(&k3.e, 4);
00101 cout << "Inserting the integer " << j4.i
00102 << " into the queue with relative order 1.\n";
00103 q3.insert(&k4.e, 1);
00104 cout << "The queue has now " << q3.size() << " elements.\n";
00105 cout << "Removing the element whose value is " << j2.i << "("
00106 << q3.remove(&k2)->object()->i << ")" << " from the queue.\n";
00107 cout << "Removing the queue's head (" << q3.remove()->object()->i
00108 << ")" << " from the queue.\n";
00109 cout << "Removing the queue's head (" << q3.remove()->object()->i
00110 << ")" << " from the queue.\n";
00111 cout << "Removing the queue's head (" << q3.remove()->object()->i
00112 << ")" << " from the queue.\n";
00113 cout << "The queue has now " << q3.size() << " elements.\n";
00114
00115 return 0;
00116 }