blob: 0447ae61aedf3e704c60bce9e6e00c0e6841fada (
plain)
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
|
#include <stdio.h>
#include "String.h"
#include "DList.h"
main ()
{
#ifdef CPLUS_BUG19
IvlDList l;
#else
IvlDListOf <char> l;
#endif
char c;
char s[80];
while ((c = getchar ()) != EOF) {
switch (c) {
case 'a':
scanf (" %s", s);
l.Append (NewString (s));
break;
case 'p':
scanf (" %s", s);
l.Prepend (NewString (s));
break;
case '+':
l.RemoveFirst ();
break;
case '-':
l.RemoveLast ();
break;
case '\n':
continue;
case 'r':
{
IvlDListIterOf <char> li (l);
li.GotoEnd ();
while (--li) {
char* pt = *li;
printf ("%s ", pt);
}
printf ("\n");
continue;
}
case 'i':
{
int i;
scanf (" %d %s", &i, s);
IvlDListIterOf <char> lj (l);
while ((i-- > 0) && ++lj)
;
l.InsertBefore (lj, NewString (s));
break;
}
case 'j':
{
int i;
scanf (" %d %s", &i, s);
IvlDListIterOf <char> lj (l);
while ((i-- > 0) && ++lj)
;
l.InsertAfter (lj, NewString (s));
break;
}
}
#ifdef CPLUS_BUG19
IvlDListIter li (l);
while (++li)
printf ("%s ", (char*) *li);
#else
IvlDListIterOf <char> li (l);
while (++li) {
char* pt = *li;
printf ("%s ", pt);
}
#endif
printf ("\n");
}
}
|