File:
[LON-CAPA] /
loncom /
types /
Queue.pm
Revision
1.4:
download - view:
text,
annotated -
select for diffs
Thu Apr 24 15:12:40 2003 UTC (21 years, 4 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 queue in terms of a list.
2: #
3: # $Id: Queue.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 Queue
31:
32: An object oriented implementation of a queue data structure. queues
33: are first in last out data structures.
34:
35: =head1 Member functions:
36:
37: =cut
38:
39: package Queue;
40:
41:
42: =pod
43:
44: =head2 new
45:
46: Construct a new queue.
47:
48: =cut
49:
50: sub new {
51: my $class = shift; # Class name to bless into.
52: my $self = []; # Our data is a reference to an anon. array.
53:
54: bless($self, $class); # Type this as an object.
55:
56: return $self;
57: }
58:
59: =pod
60:
61: =head2 enqueue
62:
63: Add an element to the tail of the queue.
64:
65: =cut
66:
67: sub enqueue {
68: my $self = shift; # Get object reference.
69: my $item = shift; # Get the item to enqueue...
70: push(@$self, $item); # Push the item to the back of the array.
71:
72:
73: }
74:
75: =pod
76:
77: =head2 dequeue
78:
79: Remove an element from the front of the queue.
80:
81: =cut
82:
83: sub dequeue {
84: my $self = shift; # Get object reference....
85: return shift @$self; # Remove from the front of the queue.
86: }
87:
88:
89: =pod
90:
91: =head1 Count
92:
93: Returns number of items in a queue.
94:
95: =cut
96:
97: sub Count {
98: my $self = shift;
99: my $count = scalar(@$self);
100: return $count;
101: }
102:
103: 1;
104:
105: =pod
106:
107: =head1 Theory
108:
109: The queue is implemented as an array... enqueue is a thinly disguised
110: push, and dequeue is a thinly disguised shift. This is probably quite
111: in efficient for large queues, but should be fine for reasonably sized
112: queues.
113:
114: Note that since Perl is a dynamically typed language, queues can
115: contain objects of any data type and can even be heterogenously typed.
116:
117: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>