forked from uva-cs/pdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListTest.cpp.html
531 lines (442 loc) · 67.9 KB
/
ListTest.cpp.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite">
<title>ListTest.cpp</title>
</head>
<body style="background-color:white">
<pre><i><span style="color:#9A1900">// Modified: 8/30/2006: mc2zk</span></i>
<i><span style="color:#9A1900">// CS216 Lab 1 - Test Harness</span></i>
<i><span style="color:#9A1900">// by Michael Crane</span></i>
<i><span style="color:#9A1900">//</span></i>
<i><span style="color:#9A1900">// Integrate this test harness with your List implementation to</span></i>
<i><span style="color:#9A1900">// thoroughly test your design. I have only used functions that were</span></i>
<i><span style="color:#9A1900">// explicitly defined in the specification, with one exception:</span></i>
<i><span style="color:#9A1900">//</span></i>
<i><span style="color:#9A1900">// I have assumed a global print function whose prototype is</span></i>
<i><span style="color:#9A1900">// void printList(List l, bool forward);</span></i>
<i><span style="color:#9A1900">//</span></i>
<i><span style="color:#9A1900">// If the 'forward' parameter is true,</span></i>
<i><span style="color:#9A1900">// the list is printed in forward order</span></i>
<i><span style="color:#9A1900">// if the 'forward' parameter is false,</span></i>
<i><span style="color:#9A1900">// the list is printed in reverse order</span></i>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><iostream></span>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><string></span>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><cctype></span>
<b><span style="color:#0000FF">using</span></b> <b><span style="color:#0000FF">namespace</span></b> std<span style="color:#990000">;</span>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000">"List.h"</span>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000">"ListItr.h"</span>
<span style="color:#009900">int</span> <b><span style="color:#000000">menu</span></b> <span style="color:#990000">(</span><span style="color:#008080">string</span> option<span style="color:#990000">[],</span> <span style="color:#009900">int</span> n_opt<span style="color:#990000">);</span>
<i><span style="color:#9A1900">//set up menu options</span></i>
<span style="color:#008080">string</span> option<span style="color:#990000">[]</span> <span style="color:#990000">=</span> <span style="color:#FF0000">{</span>
<span style="color:#FF0000">"Quit"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"New List"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Show List elements"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Set ListItr with first()"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Set ListItr with find()"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Set ListItr with last()"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Move ListItr forward"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Move ListItr backward"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Retrieve element at ListItr"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Insert element before"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Insert element after"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Insert element at tail"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Remove element"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Cardinality (size)"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Copy list w/copy constructor"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Copy list with operator="</span><span style="color:#990000">,</span>
<span style="color:#FF0000">"Make list empty"</span><span style="color:#990000">,</span>
<span style="color:#FF0000">}</span><span style="color:#990000">;</span>
<span style="color:#009900">int</span> <b><span style="color:#0000FF">const</span></b> n_choice <span style="color:#990000">=</span> <span style="color:#993399">17</span><span style="color:#990000">;</span>
<i><span style="color:#9A1900">/*</span></i>
<i><span style="color:#9A1900"> * This main driver program interactively exercises a</span></i>
<i><span style="color:#9A1900"> * list package.</span></i>
<i><span style="color:#9A1900"> * It assumes a linked list implementation, and its real</span></i>
<i><span style="color:#9A1900"> * purpose is to exercise the underlying list manipulation</span></i>
<i><span style="color:#9A1900"> * procedures.</span></i>
<i><span style="color:#9A1900"> * It uses a menu to accept commands from the terminal,</span></i>
<i><span style="color:#9A1900"> * then performs the indicated command.</span></i>
<i><span style="color:#9A1900"> */</span></i>
<span style="color:#009900">int</span> <b><span style="color:#000000">main</span></b> <span style="color:#990000">()</span> <span style="color:#FF0000">{</span>
<span style="color:#009900">int</span> command<span style="color:#990000">;</span>
<span style="color:#008080">string</span> response<span style="color:#990000">;</span>
<span style="color:#008080">List</span> <span style="color:#990000">*</span>list <span style="color:#990000">=</span> NULL<span style="color:#990000">;</span>
<span style="color:#008080">ListItr</span> <span style="color:#990000">*</span>itr <span style="color:#990000">=</span> NULL<span style="color:#990000">;</span>
<i><span style="color:#9A1900">// Initialize this run</span></i>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"--------------------------------------------------"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">This test harness operates with one List"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">object and one ListItr object."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Use the menu options to manipulate these"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">objects."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">while</span></b> <span style="color:#990000">(</span><b><span style="color:#0000FF">true</span></b><span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
command <span style="color:#990000">=</span> <b><span style="color:#000000">menu</span></b><span style="color:#990000">(</span>option<span style="color:#990000">,</span> n_choice<span style="color:#990000">);</span>
<b><span style="color:#0000FF">switch</span></b> <span style="color:#990000">(</span>command<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<i><span style="color:#9A1900">// Quit</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">1</span><span style="color:#990000">:</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Do you really want to quit? (y/n) > "</span><span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> response<span style="color:#990000">;</span>
<i><span style="color:#9A1900">// Exit normally</span></i>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>response<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]</span> <span style="color:#990000">==</span> <span style="color:#FF0000">'y'</span> <span style="color:#990000">||</span> response<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]</span> <span style="color:#990000">==</span> <span style="color:#FF0000">'Y'</span><span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">!=</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">delete</span></b> list<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr <span style="color:#990000">!=</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">delete</span></b> itr<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">return</span></b> <span style="color:#993399">0</span><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// New list</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">2</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">!=</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">delete</span></b> list<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
list <span style="color:#990000">=</span> <b><span style="color:#0000FF">new</span></b> <b><span style="color:#000000">List</span></b><span style="color:#990000">();</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">You have created an empty list"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Do you want to initialize it with elements? (y/n) > "</span><span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> response<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>response<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]</span> <span style="color:#990000">!=</span> <span style="color:#FF0000">'y'</span> <span style="color:#990000">&&</span> response<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]</span> <span style="color:#990000">!=</span> <span style="color:#FF0000">'Y'</span><span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<i><span style="color:#9A1900">// accept elements</span></i>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t\t</span><span style="color:#FF0000">Enter elements one by one as integers."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t\t</span><span style="color:#FF0000">Any non-numeric character, e.g. #, will terminate input"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Enter first element: "</span><span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> response<span style="color:#990000">;</span>
<b><span style="color:#0000FF">while</span></b> <span style="color:#990000">(</span><b><span style="color:#000000">isdigit</span></b><span style="color:#990000">(</span>response<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]))</span> <span style="color:#FF0000">{</span>
<span style="color:#009900">int</span> element <span style="color:#990000">=</span> <b><span style="color:#000000">atoi</span></b><span style="color:#990000">(</span>response<span style="color:#990000">.</span><b><span style="color:#000000">c_str</span></b><span style="color:#990000">());</span>
list<span style="color:#990000">-></span><b><span style="color:#000000">insertAtTail</span></b><span style="color:#990000">(</span>element<span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Enter next element: "</span><span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> response<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The elements in forward order: "</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">true</span></b><span style="color:#990000">);</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// Show elements</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">3</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a List first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Print the list forwards or backwards? (f/b) > "</span><span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> response<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>response<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]</span> <span style="color:#990000">==</span> <span style="color:#FF0000">'b'</span> <span style="color:#990000">||</span> response<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]</span> <span style="color:#990000">==</span> <span style="color:#FF0000">'B'</span><span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The elements in reverse order:"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">false</span></b><span style="color:#990000">);</span>
<span style="color:#FF0000">}</span> <b><span style="color:#0000FF">else</span></b> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The elements in forward order:"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">true</span></b><span style="color:#990000">);</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// first()</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">4</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a List first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Setting the ListItr to the first element..."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr <span style="color:#990000">!=</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">delete</span></b> itr<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
itr <span style="color:#990000">=</span> <b><span style="color:#0000FF">new</span></b> <b><span style="color:#000000">ListItr</span></b><span style="color:#990000">(</span>list<span style="color:#990000">-></span><b><span style="color:#000000">first</span></b><span style="color:#990000">());</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// find()</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">5</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a List first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Enter element to find: "</span><span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> response<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span><b><span style="color:#000000">isdigit</span></b><span style="color:#990000">(</span>response<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]))</span> <span style="color:#FF0000">{</span>
<span style="color:#009900">int</span> element <span style="color:#990000">=</span> <b><span style="color:#000000">atoi</span></b><span style="color:#990000">(</span>response<span style="color:#990000">.</span><b><span style="color:#000000">c_str</span></b><span style="color:#990000">());</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Setting the ListItr to find("</span> <span style="color:#990000"><<</span> element <span style="color:#990000"><<</span> <span style="color:#FF0000">")..."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr <span style="color:#990000">!=</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">delete</span></b> itr<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
itr <span style="color:#990000">=</span> <b><span style="color:#0000FF">new</span></b> <b><span style="color:#000000">ListItr</span></b><span style="color:#990000">(</span>list<span style="color:#990000">-></span><b><span style="color:#000000">find</span></b><span style="color:#990000">(</span>element<span style="color:#990000">));</span>
<span style="color:#FF0000">}</span> <b><span style="color:#0000FF">else</span></b> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Please enter an integer."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// last()</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">6</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a List first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Setting the ListItr to the last element..."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr <span style="color:#990000">!=</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">delete</span></b> itr<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
itr <span style="color:#990000">=</span> <b><span style="color:#0000FF">new</span></b> <b><span style="color:#000000">ListItr</span></b><span style="color:#990000">(</span>list<span style="color:#990000">-></span><b><span style="color:#000000">last</span></b><span style="color:#990000">());</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// moveForwards()</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">7</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a ListItr first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Moving the ListItr forwards..."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
itr<span style="color:#990000">-></span><b><span style="color:#000000">moveForward</span></b><span style="color:#990000">();</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// moveBackwards()</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">8</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a ListItr first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Moving the ListItr backwards..."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
itr<span style="color:#990000">-></span><b><span style="color:#000000">moveBackward</span></b><span style="color:#990000">();</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// retrieve()</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">9</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a ListItr first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr<span style="color:#990000">-></span><b><span style="color:#000000">isPastBeginning</span></b><span style="color:#990000">())</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">The ListItr is past the beginning."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span> <b><span style="color:#0000FF">else</span></b> <b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr<span style="color:#990000">-></span><b><span style="color:#000000">isPastEnd</span></b><span style="color:#990000">())</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">The ListItr is past the end."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span> <b><span style="color:#0000FF">else</span></b> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Element retrieved: "</span> <span style="color:#990000"><<</span> itr<span style="color:#990000">-></span><b><span style="color:#000000">retrieve</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// insertBefore()</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">10</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">==</span> NULL <span style="color:#990000">||</span> itr <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a List and ListItr first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr<span style="color:#990000">-></span><b><span style="color:#000000">isPastBeginning</span></b><span style="color:#990000">())</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Cannot insert past the beginning of the list."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Enter element to insert: "</span><span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> response<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span><b><span style="color:#000000">isdigit</span></b><span style="color:#990000">(</span>response<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]))</span> <span style="color:#FF0000">{</span>
<span style="color:#009900">int</span> element <span style="color:#990000">=</span> <b><span style="color:#000000">atoi</span></b><span style="color:#990000">(</span>response<span style="color:#990000">.</span><b><span style="color:#000000">c_str</span></b><span style="color:#990000">());</span>
list<span style="color:#990000">-></span><b><span style="color:#000000">insertBefore</span></b><span style="color:#990000">(</span>element<span style="color:#990000">,</span> <span style="color:#990000">*</span>itr<span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Inserting "</span> <span style="color:#990000"><<</span> element <span style="color:#990000"><<</span> <span style="color:#FF0000">" before the current ListItr"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span> <b><span style="color:#0000FF">else</span></b> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Please enter an integer."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The elements in forward order: "</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">true</span></b><span style="color:#990000">);</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// insertAfter()</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">11</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">==</span> NULL <span style="color:#990000">||</span> itr <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a List and ListItr first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr<span style="color:#990000">-></span><b><span style="color:#000000">isPastEnd</span></b><span style="color:#990000">())</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Cannot insert past the end of the list."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Enter element to insert: "</span><span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> response<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span><b><span style="color:#000000">isdigit</span></b><span style="color:#990000">(</span>response<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]))</span> <span style="color:#FF0000">{</span>
<span style="color:#009900">int</span> element <span style="color:#990000">=</span> <b><span style="color:#000000">atoi</span></b><span style="color:#990000">(</span>response<span style="color:#990000">.</span><b><span style="color:#000000">c_str</span></b><span style="color:#990000">());</span>
list<span style="color:#990000">-></span><b><span style="color:#000000">insertAfter</span></b><span style="color:#990000">(</span>element<span style="color:#990000">,</span> <span style="color:#990000">*</span>itr<span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Inserting "</span> <span style="color:#990000"><<</span> element <span style="color:#990000"><<</span> <span style="color:#FF0000">" after the current ListItr"</span> <span style="color:#990000"><<</span>endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span> <b><span style="color:#0000FF">else</span></b> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Please enter an integer."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The elements in forward order: "</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">true</span></b><span style="color:#990000">);</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// insertAtTail()</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">12</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a List first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Enter element to insert: "</span><span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> response<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span><b><span style="color:#000000">isdigit</span></b><span style="color:#990000">(</span>response<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]))</span> <span style="color:#FF0000">{</span>
<span style="color:#009900">int</span> element <span style="color:#990000">=</span> <b><span style="color:#000000">atoi</span></b><span style="color:#990000">(</span>response<span style="color:#990000">.</span><b><span style="color:#000000">c_str</span></b><span style="color:#990000">());</span>
list<span style="color:#990000">-></span><b><span style="color:#000000">insertAtTail</span></b><span style="color:#990000">(</span>element<span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Inserting "</span> <span style="color:#990000"><<</span> element <span style="color:#990000"><<</span> <span style="color:#FF0000">" at the tail of the list"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span> <b><span style="color:#0000FF">else</span></b> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Please enter an integer."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The elements in forward order: "</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">true</span></b><span style="color:#990000">);</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// remove()</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">13</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a List first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Enter element to remove: "</span><span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> response<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span><b><span style="color:#000000">isdigit</span></b><span style="color:#990000">(</span>response<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]))</span> <span style="color:#FF0000">{</span>
<span style="color:#009900">int</span> element <span style="color:#990000">=</span> <b><span style="color:#000000">atoi</span></b><span style="color:#990000">(</span>response<span style="color:#990000">.</span><b><span style="color:#000000">c_str</span></b><span style="color:#990000">());</span>
list<span style="color:#990000">-></span><b><span style="color:#000000">remove</span></b><span style="color:#990000">(</span>element<span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Removing "</span> <span style="color:#990000"><<</span> element <span style="color:#990000"><<</span> <span style="color:#FF0000">" from list"</span> <span style="color:#990000"><<</span>endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span> <b><span style="color:#0000FF">else</span></b> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Please enter an integer."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The elements in forward order: "</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">true</span></b><span style="color:#990000">);</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// size()</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">14</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a List first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Size of list: "</span> <span style="color:#990000"><<</span> list<span style="color:#990000">-></span><b><span style="color:#000000">size</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// Copy constructor</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">15</span><span style="color:#990000">:</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a List first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
List<span style="color:#990000">*</span> old_list <span style="color:#990000">=</span> list<span style="color:#990000">;</span>
list <span style="color:#990000">=</span> <b><span style="color:#0000FF">new</span></b> <b><span style="color:#000000">List</span></b><span style="color:#990000">(*</span>old_list<span style="color:#990000">);</span>
old_list<span style="color:#990000">-></span><b><span style="color:#000000">makeEmpty</span></b><span style="color:#990000">();</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The new list is (forward): "</span><span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">true</span></b><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The new list is (backward): "</span><span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">false</span></b><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The old list was made empty (forward): "</span><span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>old_list<span style="color:#990000">,</span> <b><span style="color:#0000FF">true</span></b><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The old list was made empty (backward): "</span><span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>old_list<span style="color:#990000">,</span> <b><span style="color:#0000FF">false</span></b><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The old list should be destroyed now."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">delete</span></b> old_list<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr <span style="color:#990000">!=</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">delete</span></b> itr<span style="color:#990000">;</span>
itr <span style="color:#990000">=</span> NULL<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<i><span style="color:#9A1900">// operator=</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">16</span><span style="color:#990000">:</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a List first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
List<span style="color:#990000">*</span> old_list <span style="color:#990000">=</span> list<span style="color:#990000">;</span>
list <span style="color:#990000">=</span> <b><span style="color:#0000FF">new</span></b> <b><span style="color:#000000">List</span></b><span style="color:#990000">();</span>
<span style="color:#990000">*</span>list <span style="color:#990000">=</span> <span style="color:#990000">*</span>old_list<span style="color:#990000">;</span>
old_list<span style="color:#990000">-></span><b><span style="color:#000000">makeEmpty</span></b><span style="color:#990000">();</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The new list is (forward): "</span><span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">true</span></b><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The new list is (backward): "</span><span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">false</span></b><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The old list was made empty (forward): "</span><span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>old_list<span style="color:#990000">,</span> <b><span style="color:#0000FF">true</span></b><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The old list was made empty (backward): "</span><span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>old_list<span style="color:#990000">,</span> <b><span style="color:#0000FF">false</span></b><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The old list should be destroyed now."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">delete</span></b> old_list<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr <span style="color:#990000">!=</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">delete</span></b> itr<span style="color:#990000">;</span>
itr <span style="color:#990000">=</span> NULL<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<i><span style="color:#9A1900">// makeEmpty()</span></i>
<b><span style="color:#0000FF">case</span></b> <span style="color:#993399">17</span><span style="color:#990000">:</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>list <span style="color:#990000">==</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Create a List first."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">break</span></b><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The list is (forward): "</span><span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">true</span></b><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The list is (backward): "</span><span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">false</span></b><span style="color:#990000">);</span>
list<span style="color:#990000">-></span><b><span style="color:#000000">makeEmpty</span></b><span style="color:#990000">();</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>itr <span style="color:#990000">!=</span> NULL<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">delete</span></b> itr<span style="color:#990000">;</span>
itr <span style="color:#990000">=</span> NULL<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The list was made empty (forward): "</span><span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">true</span></b><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The list was made empty (backward): "</span><span style="color:#990000">;</span>
<b><span style="color:#000000">printList</span></b><span style="color:#990000">(*</span>list<span style="color:#990000">,</span> <b><span style="color:#0000FF">false</span></b><span style="color:#990000">);</span>
<span style="color:#FF0000">}</span>
<span style="color:#FF0000">}</span>
<span style="color:#FF0000">}</span>
<i><span style="color:#9A1900">/*</span></i>
<i><span style="color:#9A1900"> * This simple routine takes an array of 'n_opt' options</span></i>
<i><span style="color:#9A1900"> * (pointers to strings, describing the 'option')</span></i>
<i><span style="color:#9A1900"> * displays these options on the screen,</span></i>
<i><span style="color:#9A1900"> * and requests a choice on the part of the user</span></i>
<i><span style="color:#9A1900"> * It returns the integer number (position in the list)</span></i>
<i><span style="color:#9A1900"> * of the chosen option.</span></i>
<i><span style="color:#9A1900"> *</span></i>
<i><span style="color:#9A1900"> * NOTE, all input and output uses 'stdin' and 'stdout'</span></i>
<i><span style="color:#9A1900">*/</span></i>
<span style="color:#009900">int</span> <b><span style="color:#000000">menu</span></b> <span style="color:#990000">(</span><span style="color:#008080">string</span> option<span style="color:#990000">[],</span> <span style="color:#009900">int</span> n_opt<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<span style="color:#009900">int</span> choice<span style="color:#990000">,</span> i<span style="color:#990000">;</span>
<span style="color:#008080">string</span> input<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">" - - - - - - MENU - - - - - -"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">for</span></b> <span style="color:#990000">(</span>i <span style="color:#990000">=</span> <span style="color:#993399">0</span><span style="color:#990000">;</span> i <span style="color:#990000"><</span> n_opt<span style="color:#990000">;</span> i<span style="color:#990000">++)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">"</span> <span style="color:#990000"><<</span> i <span style="color:#990000">+</span> <span style="color:#993399">1</span> <span style="color:#990000"><<</span> <span style="color:#FF0000">" - "</span> <span style="color:#990000"><<</span> option<span style="color:#990000">[</span>i<span style="color:#990000">]</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">" - - - - - - - - - - - - - - -"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">while</span></b> <span style="color:#990000">(</span>input<span style="color:#990000">.</span><b><span style="color:#000000">empty</span></b><span style="color:#990000">())</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">" Enter number of choice > "</span><span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> input<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span><b><span style="color:#000000">isdigit</span></b><span style="color:#990000">(</span>input<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]))</span> <span style="color:#FF0000">{</span>
choice <span style="color:#990000">=</span> <b><span style="color:#000000">atoi</span></b><span style="color:#990000">(</span>input<span style="color:#990000">.</span><b><span style="color:#000000">c_str</span></b><span style="color:#990000">());</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>choice <span style="color:#990000"><=</span> n_opt <span style="color:#990000">&&</span> choice <span style="color:#990000">></span> <span style="color:#993399">0</span><span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">return</span></b> choice<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span> <b><span style="color:#0000FF">else</span></b> <span style="color:#FF0000">{</span>
<i><span style="color:#9A1900">/* choice out of range */</span></i>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Your response MUST be between 1 and "</span> <span style="color:#990000"><<</span> n_opt <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
input<span style="color:#990000">.</span><b><span style="color:#000000">clear</span></b><span style="color:#990000">();</span>
<span style="color:#FF0000">}</span>
<span style="color:#FF0000">}</span> <b><span style="color:#0000FF">else</span></b> <span style="color:#FF0000">{</span>
<i><span style="color:#9A1900">/* Non-numeric input, ignore */</span></i>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">Your response MUST be a number!"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
input<span style="color:#990000">.</span><b><span style="color:#000000">clear</span></b><span style="color:#990000">();</span>
<span style="color:#FF0000">}</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">return</span></b> <span style="color:#993399">1</span><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
</pre>
</body>
</html>