summaryrefslogtreecommitdiff
path: root/utils/testchain.cc
blob: 04351f596a3555d5ff241062a43fcf6de0790498 (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
#include <stdio.h>
#include "String.h"
#include "Chain.h"

class C {
public:
	C*	Next;
	char* IvlString;
inline		C (const char* c) : Next (0), IvlString (NewString (c))	{}
inline	C*	GetNext () const	{ /*printf ("GetNext (%x) = %x)\n", this, Next); */ return Next; }
inline	void	SetNext (C* c) 	{ /*printf ("SetNext (%x, %x)\n", this, c); */ Next = c; }
};

main ()
{
	IvlChainOf <C> l;
	char c;
	char s[80];
	while ((c = getchar ()) != EOF) {
		switch (c) {
		case 'a':
			scanf (" %s", s);
			l.Append (new C (s));
			break;
		case 'p':
			scanf (" %s", s);
			l.Prepend (new C (s));
			break;
		case '+':
			l.RemoveFirst ();
			break;
		case '-':
			l.RemoveLast ();
			break;
		case '\n':
			continue;
		case 'i':
			{
			int i;
			scanf (" %d %s", &i, s);
			IvlChainIterOf <C> lj (l);
			while ((i-- > 0) && ++lj)
				;
			l.InsertBefore (lj, new C (s));
			break;
			}
		case 'j':
			{
			int i;
			scanf (" %d %s", &i, s);
			IvlChainIterOf <C> lj (l);
			while ((i-- > 0) && ++lj)
				;
			l.InsertAfter (lj, new C (s));
			break;
			}
		}
		IvlChainIterOf <C> li (l);
		while (++li) {
			C* pt = *li;
			printf ("%s ", pt->IvlString);
		}
		printf ("\n");
	}
}