File:
[LON-CAPA] /
loncom /
types /
Stack.pm
Revision
1.4:
download - view:
text,
annotated -
select for diffs
Thu Apr 24 15:12:40 2003 UTC (21 years, 3 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_X,
version_2_8_99_1,
version_2_8_99_0,
version_2_8_2,
version_2_8_1,
version_2_8_0,
version_2_7_X,
version_2_7_99_1,
version_2_7_99_0,
version_2_7_1,
version_2_7_0,
version_2_6_X,
version_2_6_99_1,
version_2_6_99_0,
version_2_6_3,
version_2_6_2,
version_2_6_1,
version_2_6_0,
version_2_5_X,
version_2_5_99_1,
version_2_5_99_0,
version_2_5_2,
version_2_5_1,
version_2_5_0,
version_2_4_X,
version_2_4_99_0,
version_2_4_2,
version_2_4_1,
version_2_4_0,
version_2_3_X,
version_2_3_99_0,
version_2_3_2,
version_2_3_1,
version_2_3_0,
version_2_2_X,
version_2_2_99_1,
version_2_2_99_0,
version_2_2_2,
version_2_2_1,
version_2_2_0,
version_2_1_X,
version_2_1_99_3,
version_2_1_99_2,
version_2_1_99_1,
version_2_1_99_0,
version_2_1_3,
version_2_1_2,
version_2_1_1,
version_2_1_0,
version_2_12_X,
version_2_11_X,
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
version_2_11_1,
version_2_11_0_RC3,
version_2_11_0_RC2,
version_2_11_0_RC1,
version_2_11_0,
version_2_10_X,
version_2_10_1,
version_2_10_0_RC2,
version_2_10_0_RC1,
version_2_10_0,
version_2_0_X,
version_2_0_99_1,
version_2_0_2,
version_2_0_1,
version_2_0_0,
version_1_99_3,
version_1_99_2,
version_1_99_1_tmcc,
version_1_99_1,
version_1_99_0_tmcc,
version_1_99_0,
version_1_3_X,
version_1_3_3,
version_1_3_2,
version_1_3_1,
version_1_3_0,
version_1_2_X,
version_1_2_99_1,
version_1_2_99_0,
version_1_2_1,
version_1_2_0,
version_1_1_X,
version_1_1_99_5,
version_1_1_99_4,
version_1_1_99_3,
version_1_1_99_2,
version_1_1_99_1,
version_1_1_99_0,
version_1_1_3,
version_1_1_2,
version_1_1_1,
version_1_1_0,
version_1_0_99_3,
version_1_0_99_2,
version_1_0_99_1,
version_1_0_99,
version_1_0_3,
version_1_0_2,
version_1_0_1,
version_1_0_0,
version_0_99_5,
version_0_99_4,
version_0_99_3,
version_0_99_2,
version_0_99_1,
version_0_99_0,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
conference_2003,
bz6209-base,
bz6209,
bz5969,
bz2851,
PRINT_INCOMPLETE_base,
PRINT_INCOMPLETE,
HEAD,
GCI_3,
GCI_2,
GCI_1,
BZ5971-printing-apage,
BZ5434-fox,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse
- fixing pod
1: # Implement a simple stack in terms of a list.
2: #
3: # $Id: Stack.pm,v 1.4 2003/04/24 15:12:40 albertel Exp $
4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27:
28: =pod
29:
30: =head1 Stack
31:
32: An object oriented implementation of a Stack data structure.
33: Stacks are first in last out data structures.
34:
35: =head1 Member functions:
36:
37: =cut
38:
39: package Stack;
40:
41: =pod
42:
43: =head2 new
44:
45: Creates a new instance of a stack.
46:
47: my $stack = Stack->new();
48:
49: =cut
50:
51: sub new {
52: my $class = shift; # Class name.
53: my $self = []; # Create an empty list to represent the stack.
54: bless($self, $class); # Turn this into an object and..
55: return $self; # Return it.
56: }
57:
58: =pod
59:
60: =head2 push
61:
62: takes an item and pushes it onto the back end of the stack.
63:
64: my $stack = Stack->new();
65: $stack->push(something);
66:
67: =cut
68:
69: sub push {
70: my $self = shift; # Gets the list...
71: my $item = shift; # The item to push.
72: push(@$self,$item);
73: }
74:
75: =pod
76:
77: =head2 pop
78:
79: Returns the item at the top of the stack: does a pop.
80:
81: my object = Stack->new();
82: my $item = object->pop();
83:
84: =cut
85:
86: sub pop {
87: my $self = shift;
88: return pop(@$self);
89: }
90:
91: =pod
92:
93: =head 1
94:
95: Returns the number of items on the stack.
96:
97: =cut
98:
99: sub Count {
100: my $self = shift;
101: my $elements = scalar(@$self);
102: return $elements;
103: }
104:
105: 1;
106:
107: =pod
108:
109: =head1 Internal implementation details
110:
111: Stacks are implemented as lists. Thus a stack is a thinly disguised
112: list with push and pop wrappers. Since PERL is a dynamically typed
113: language, stacks can contain any data type ... including a
114: heterogenous collection of types.
115:
116: =cut
117:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>