--- a/Queue.st Fri Nov 17 17:54:08 1995 +0100
+++ b/Queue.st Thu Nov 23 02:17:16 1995 +0100
@@ -33,10 +33,6 @@
"
!
-version
- ^ '$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.13 1995-11-11 15:21:32 cg Exp $'
-!
-
documentation
"
Queues provides a simple implementation of a queue, where
@@ -54,10 +50,20 @@
See SharedQueue for a class which is safe with processes and blocks
on write when full or on read when empty.
"
+!
+
+version
+ ^ '$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.14 1995-11-23 01:17:16 cg Exp $'
! !
!Queue class methodsFor:'instance creation'!
+new
+ "return a new queue with space for some elements"
+
+ ^ self new:50
+!
+
new:size
"return a new queue with space for size elements"
@@ -84,34 +90,10 @@
Transcript show:(q next); space.
Transcript showCr:(q next).
"
-!
-
-new
- "return a new queue with space for some elements"
-
- ^ self new:50
-! !
-
-!Queue methodsFor:'initialization'!
-
-init:size
- "initialize the receiver for size entries"
-
- contentsArray := Array new:size.
- readPosition := writePosition := 1.
- tally := 0.
! !
!Queue methodsFor:'accessing'!
-peek
- "return the next value in the queue without removing it.
- If the queue is empty, return nil."
-
- (tally == 0) ifTrue:[^ nil].
- ^ contentsArray at:readPosition.
-!
-
next
"return the next value in the queue;
Return nil, if the queue is empty"
@@ -154,6 +136,14 @@
"enter all elements from aCollection into the queue."
aCollection do:[:element | self nextPut:element]
+!
+
+peek
+ "return the next value in the queue without removing it.
+ If the queue is empty, return nil."
+
+ (tally == 0) ifTrue:[^ nil].
+ ^ contentsArray at:readPosition.
! !
!Queue methodsFor:'enumerating'!
@@ -174,8 +164,24 @@
]
! !
+!Queue methodsFor:'initialization'!
+
+init:size
+ "initialize the receiver for size entries"
+
+ contentsArray := Array new:size.
+ readPosition := writePosition := 1.
+ tally := 0.
+! !
+
!Queue methodsFor:'queries'!
+capacity
+ "return the number of elements the queue can hold"
+
+ ^ contentsArray size
+!
+
isEmpty
"return true, if there are no elements in the queue"
@@ -193,10 +199,5 @@
"return the number of elements in the queue"
^ tally
-!
+! !
-capacity
- "return the number of elements the queue can hold"
-
- ^ contentsArray size
-! !