chiark / gitweb /
Qualify name given to @bres_byname@.
[mLib] / da-ref
CommitLineData
d74e2a35 1#! /usr/bin/perl
2#
3# Reference implementation for dynamic array testing.
4
5@a = ();
6while (<>) {
7 chomp();
8 # print "$_\n";
9 @F = split();
10 if ($F[0] eq "push") {
11 push(@a, $F[1]);
12 } elsif ($F[0] eq "unshift") {
13 unshift(@a, $F[1]);
14 } elsif ($F[0] eq "pop") {
15 if (@a == 0) {
16 print "*UFLOW*\n";
17 } else {
18 my $n = int(pop(@a));
19 print "$n\n";
20 }
21 } elsif ($F[0] eq "shift") {
22 if (@a == 0) {
23 print "*UFLOW*\n";
24 } else {
25 my $n = int(shift(@a));
26 print "$n\n";
27 }
28 } elsif ($F[0] eq "insert") {
29 shift(@F);
30 unshift(@a, @F);
31 } elsif ($F[0] eq "append") {
32 shift(@F);
33 push(@a, @F);
34 } elsif ($F[0] eq "delete") {
35 if ($F[1] > @a) {
36 # @a = ();
37 print "*UFLOW*\n";
38 } else {
39 splice(@a, 0, $F[1]);
40 }
41 } elsif ($F[0] eq "reduce") {
42 if ($F[1] > @a) {
43 # @a = ();
44 print "*UFLOW*\n";
45 } else {
46 $#a -= $F[1];
47 }
48 } elsif ($F[0] eq "set") {
49 if ($F[1] > @a) {
50 for (my $i = @a; $i < $F[1]; $i++) { $a[$i] = -1; }
51 }
52 $a[$F[1]] = int($F[2]);
53 } elsif ($F[0] eq "get") {
54 if ($F[1] >= @a) {
55 print "*RANGE*\n";
56 } else {
57 print int($a[$F[1]]), "\n";
58 }
706bf01d 59 } elsif ($F[0] eq "first") {
60 print int($a[0]), "\n";
61 } elsif ($F[0] eq "last") {
62 print int($a[$#a]), "\n";
d74e2a35 63 } elsif ($F[0] eq "show") {
64 if (@a) {
65 print join(" ", map int, @a), "\n";
66 } else {
67 print "*EMPTY*\n";
68 }
69 } else {
70 print "*BAD*\n";
71 }
72}