Edinburgh Speech Tools  2.1-release
deq_example.cc
Go to the documentation of this file.
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 using namespace std;
45 
46 
47 /**@name EST_TDeque:example
48  *
49  * Examples of stack and queue use.
50  *
51  * @see EST_TDeque
52  */
53 //@{
54 //{ code
55 int main(void)
56 {
57  EST_String strings[]
58  = { "Argyle", "Bute", "Cumbernauld", "Dundee", "Edinburgh", "Fife",
59  "Glasgow", "Harris", "Iona", "Jura", "Kirkwald", "Lewis",
60  "Mull", "Newhaven", "Orkney", "Pitlochry", "Queensferry",
61  };
62 
63  EST_TDeque<EST_String> deq(5,2);
64 
65  int i=0;
66 
67  deq.push(strings[i++]);
68  deq.push(strings[i++]);
69  deq.push(strings[i++]);
70 
71  cout << deq << "\n";
72 
73  cout << "0: " << deq.nth(0) << "\n";
74  cout << "1: " << deq.nth(1) << "\n";
75 
76  cout << deq.pop() << "\n";
77  cout << deq.pop() << "\n";
78 
79  cout << deq << "\n";
80 
81  deq.push(strings[i++]);
82  deq.push(strings[i++]);
83  deq.push(strings[i++]);
84  deq.push(strings[i++]);
85  deq.push(strings[i++]);
86  deq.push(strings[i++]);
87 
88  cout << deq << "\n";
89 
90  cout << deq.back_pop() << "\n";
91  cout << deq.back_pop() << "\n";
92  cout << deq.back_pop() << "\n";
93  cout << deq.back_pop() << "\n";
94 
95  cout << deq << "\n";
96 
97  deq.push(strings[i++]);
98  deq.push(strings[i++]);
99  deq.push(strings[i++]);
100  deq.push(strings[i++]);
101 
102  cout << deq << "\n";
103 
104  cout << "0: " << deq.nth(0) << "\n";
105  cout << "1: " << deq.nth(1) << "\n";
106  cout << "2: " << deq.nth(2) << "\n";
107  cout << "3: " << deq.nth(3) << "\n";
108 
109  deq.push(strings[i++]);
110  deq.push(strings[i++]);
111  deq.push(strings[i++]);
112  deq.push(strings[i++]);
113 
114  cout << deq << "\n";
115 
116  deq.clear();
117  i=0;
118  deq.push(strings[i++]);
119  deq.push(strings[i++]);
120  cout << deq << "\n";
121 
122  deq.back_push(strings[i++]);
123  deq.back_push(strings[i++]);
124  cout << deq << "\n";
125 
126 }
127 //@} code
128 
129 //@}
130 
131 // we would need to include the following template
132 // declarations if deqs of strings weren't already declared
133 
134 // Declare_TDEQ_Class(EST_String, "FILLER")
135 
136 // #if defined(INSTANTIATE_TEMPLATES)
137 
138 // #include "../base_class/EST_TDeque.cc"
139 
140 // Instantiate_TDEQ(EST_String)
141 
142 // #endif
143 
144 
void push(T &item)
Definition: EST_TDeque.cc:148
T & nth(int i)
Definition: EST_TDeque.cc:180
int main(void)
Definition: deq_example.cc:55