Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
deq_example.cc
1  /*************************************************************************/
2  /* */
3  /* Centre for Speech Technology Research */
4  /* University of Edinburgh, UK */
5  /* Copyright (c) 1996,1997 */
6  /* All Rights Reserved. */
7  /* Permission is hereby granted, free of charge, to use and distribute */
8  /* this software and its documentation without restriction, including */
9  /* without limitation the rights to use, copy, modify, merge, publish, */
10  /* distribute, sublicense, and/or sell copies of this work, and to */
11  /* permit persons to whom this work is furnished to do so, subject to */
12  /* the following conditions: */
13  /* 1. The code must retain the above copyright notice, this list of */
14  /* conditions and the following disclaimer. */
15  /* 2. Any modifications must be clearly marked as such. */
16  /* 3. Original authors' names are not deleted. */
17  /* 4. The authors' names are not used to endorse or promote products */
18  /* derived from this software without specific prior written */
19  /* permission. */
20  /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
21  /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
22  /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
23  /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
24  /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
25  /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
26  /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
27  /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
28  /* THIS SOFTWARE. */
29  /* */
30  /*************************************************************************/
31  /* */
32  /* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
33  /* Date: Tue Jul 22 1997 */
34  /* --------------------------------------------------------------------- */
35  /* Example of list class use. */
36  /* */
37  /*************************************************************************/
38 
39 #include <cstdlib>
40 #include <iostream>
41 #include "EST_TDeque.h"
42 #include "EST_String.h"
43 
44 
45 /**@name EST_TDeque:example
46  *
47  * Examples of stack and queue use.
48  *
49  * @see EST_TDeque
50  */
51 //@{
52 //{ code
53 int main(void)
54 {
55  EST_String strings[]
56  = { "Argyle", "Bute", "Cumbernauld", "Dundee", "Edinburgh", "Fife",
57  "Glasgow", "Harris", "Iona", "Jura", "Kirkwald", "Lewis",
58  "Mull", "Newhaven", "Orkney", "Pitlochry", "Queensferry",
59  };
60 
61  EST_TDeque<EST_String> deq(5,2);
62 
63  int i=0;
64 
65  deq.push(strings[i++]);
66  deq.push(strings[i++]);
67  deq.push(strings[i++]);
68 
69  cout << deq << "\n";
70 
71  cout << "0: " << deq.nth(0) << "\n";
72  cout << "1: " << deq.nth(1) << "\n";
73 
74  cout << deq.pop() << "\n";
75  cout << deq.pop() << "\n";
76 
77  cout << deq << "\n";
78 
79  deq.push(strings[i++]);
80  deq.push(strings[i++]);
81  deq.push(strings[i++]);
82  deq.push(strings[i++]);
83  deq.push(strings[i++]);
84  deq.push(strings[i++]);
85 
86  cout << deq << "\n";
87 
88  cout << deq.back_pop() << "\n";
89  cout << deq.back_pop() << "\n";
90  cout << deq.back_pop() << "\n";
91  cout << deq.back_pop() << "\n";
92 
93  cout << deq << "\n";
94 
95  deq.push(strings[i++]);
96  deq.push(strings[i++]);
97  deq.push(strings[i++]);
98  deq.push(strings[i++]);
99 
100  cout << deq << "\n";
101 
102  cout << "0: " << deq.nth(0) << "\n";
103  cout << "1: " << deq.nth(1) << "\n";
104  cout << "2: " << deq.nth(2) << "\n";
105  cout << "3: " << deq.nth(3) << "\n";
106 
107  deq.push(strings[i++]);
108  deq.push(strings[i++]);
109  deq.push(strings[i++]);
110  deq.push(strings[i++]);
111 
112  cout << deq << "\n";
113 
114  deq.clear();
115  i=0;
116  deq.push(strings[i++]);
117  deq.push(strings[i++]);
118  cout << deq << "\n";
119 
120  deq.back_push(strings[i++]);
121  deq.back_push(strings[i++]);
122  cout << deq << "\n";
123 
124 }
125 //@} code
126 
127 //@}
128 
129 // we would need to include the following template
130 // declarations if deqs of strings weren't already declared
131 
132 // Declare_TDEQ_Class(EST_String, "FILLER")
133 
134 // #if defined(INSTANTIATE_TEMPLATES)
135 
136 // #include "../base_class/EST_TDeque.cc"
137 
138 // Instantiate_TDEQ(EST_String)
139 
140 // #endif
141 
142