initial
[prop.git] / lib-src / contain / qa.cc
blob73bbe2615e921858496fbcbe16595e741973bdc6
1 //////////////////////////////////////////////////////////////////////////////
2 // NOTICE:
3 //
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are free to incorporate any part of ADLib and Prop into
9 // your programs.
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
16 // code.
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
21 // Allen Leung
22 // 1994
23 //////////////////////////////////////////////////////////////////////////////
25 #include <stdio.h>
26 #include <assert.h>
27 #include <AD/contain/array.h> // Arrays
28 #include <AD/contain/arraycol.h> // Array collections
29 #include <AD/contain/charset.h> // Set of ASCII characters
30 #include <AD/contain/dchbag.h> // Multiset
31 #include <AD/contain/dchset.h> // Set
32 #include <AD/contain/dchmap.h> // Associative table
33 #include <AD/contain/fixstack.h> // Fixed sized stack
34 #include <AD/contain/fixqueue.h> // Fixed sized queue
35 #include <AD/contain/intset.h> // Set of integers
36 #include <AD/contain/linklist.h> // Linked lists
37 #include <AD/contain/priqueue.h> // Priority queue
38 #include <AD/contain/queue.h> // Queues
39 #include <AD/contain/seq.h> // Sequences
40 #include <AD/contain/stack.h> // Stacks
41 #include <AD/contain/unionfnd.h> // Union find data structure
42 #include <AD/contain/vararray.h> // Variable sized array
43 #include <AD/contain/varqueue.h> // Variable sized queue
44 #include <AD/contain/varstack.h> // Variable sized stack
46 int main(int argc, char * argv[])
47 { CharSet C;
48 DCHBag<char *> bag;
49 DCHSet<char *> set;
50 DCHMap<char *,char *> M;
51 FixStack<int,100> S;
52 VarStack<char *> s1, s2;
53 Seq<char> text;
54 PriQueue<int, Array<int> > pq(256);
55 LinkedList<char *> list;
56 VarArray<char *> array(0,3);
58 C.clear();
59 C += 'a';
60 C += 'b';
61 assert(C.size() == 2);
63 S.push(1); S.push(2); S.push(3);
64 S.pop();
65 assert(S.size() == 2);
67 s1.push("allen"); s1.push("leung");
68 s2 = s1;
69 s2.pop();
70 assert(s1.size() == 2);
71 assert(s2.size() == 1);
73 M[ "John" ] = "Gleese";
74 M[ "Neal" ] = "Skyer";
75 M[ "Freud" ] = "Fraud";
76 M[ "Judy" ] = "Davis";
77 M[ "Robert" ] = "DeNiro";
78 M[ "Lawrence" ] = "Oliver";
79 M[ "Woody" ] = "Allen";
80 M[ "Harrison" ] = "Ford";
81 M[ "Mickey" ] = "Rourke";
82 M[ "Humphry" ] = "Bogart";
84 for (Ix i = M.first(); i; i = M.next(i))
85 printf("First = %s, last = %s\n", M.key(i), M.value(i));
87 assert(M.size() == 10);
89 ((list += "Bell") += "Cleary") += "Witten";
91 assert(list.length() == 3);
93 for (LinkedListIter<char *> j = list; j; j++)
94 printf("Name = %s\n", j());
96 array[0] = "Eva";
97 array[1] = "Luna";
98 array[2] = "Isaac";
99 array[3] = "Albeniz";
100 array[4] = "Villa";
101 array[5] = "Lobos";
102 array[-2] = "Manuel";
103 array[-1] = "Ponce";
105 for (int n = -2; n <= 5; n++)
106 printf("array[%d] = %s\n", n, array[n]);
108 VarQueue<int> VQ;
109 for (n = 0; n < 20; n++)
110 VQ.insertTail(n);
111 while (! VQ.isEmpty()) {
112 printf("%d ",VQ.removeHead());
114 printf("\n");
116 ArrayCollection< int, Array<int> > ac;
118 printf("OK\n");
119 return 0;