added do:, nextPutAll:
authorclaus
Mon, 22 Aug 1994 14:12:17 +0200
changeset 39 47fc4acc24db
parent 38 a7cc05fcf0dc
child 40 3686f43e20ea
added do:, nextPutAll:
Queue.st
--- a/Queue.st	Thu Aug 11 23:39:42 1994 +0200
+++ b/Queue.st	Mon Aug 22 14:12:17 1994 +0200
@@ -21,7 +21,7 @@
 COPYRIGHT (c) 1993 by Claus Gittinger
               All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.4 1994-08-05 00:59:31 claus Exp $
+$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.5 1994-08-22 12:12:17 claus Exp $
 '!
 
 !Queue class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.4 1994-08-05 00:59:31 claus Exp $
+$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.5 1994-08-22 12:12:17 claus Exp $
 "
 !
 
@@ -66,30 +66,22 @@
      |q|
 
      q := Queue new.
-     q nextPut:1.
-     q nextPut:2.
-     q nextPut:3.
-     q nextPut:4.
-     q nextPut:5.
-     Transcript show:(q next) printString; space.
-     Transcript show:(q next) printString; space.
-     Transcript show:(q next) printString; space.
-     Transcript show:(q next) printString; space.
-     q nextPut:6.
-     q nextPut:7.
-     q nextPut:8.
-     q nextPut:9.
-     q nextPut:10.
-     Transcript show:(q next) printString; space.
-     Transcript show:(q next) printString; space.
-     Transcript show:(q next) printString; space.
-     Transcript show:(q next) printString; space.
-     Transcript show:(q next) printString; space.
-     Transcript show:(q next) printString; space.
-     Transcript show:(q next) printString; space.
-     Transcript show:(q next) printString; space.
-     Transcript show:(q next) printString; space.
-     Transcript show:(q next) printString; space.
+     (1 to:5) do:[:i | q nextPut:i].
+     Transcript show:(q next); space.
+     Transcript show:(q next); space.
+     Transcript show:(q next); space.
+     Transcript show:(q next); space.
+     q nextPutAll:(6 to:10).
+     Transcript show:(q next); space.
+     Transcript show:(q next); space.
+     Transcript show:(q next); space.
+     Transcript show:(q next); space.
+     Transcript show:(q next); space.
+     Transcript show:(q next); space.
+     Transcript show:(q next); space.
+     Transcript show:(q next); space.
+     Transcript show:(q next); space.
+     Transcript showCr:(q next).
     "
 !
 
@@ -112,7 +104,8 @@
 !Queue methodsFor:'accessing'!
 
 next
-    "return the next value in the queue; if it its empty, return nil"
+    "return the next value in the queue; 
+     Return nil, if the queue is empty"
 
     |value|
 
@@ -139,6 +132,30 @@
         writePosition := 1
     ].
     tally := tally + 1
+!
+
+nextPutAll:aCollection
+    "enter all elements from aCollection into the queue."
+
+    aCollection do:[:element | self nextPut:element]
+! !
+
+!Queue methodsFor:'enumeration'!
+
+do:aBlock
+    "evaluate the argument, aBlock for each element in the queue"
+
+    |pos endPos|
+
+    pos := readPosition.
+    endPos := writePosition.
+    1 to:tally do:[:i |
+        aBlock value:(contentsArray at:pos).
+        pos := pos + 1.
+        pos > contentsArray size ifTrue:[
+            pos := 1
+        ]
+    ]
 ! !
 
 !Queue methodsFor:'queries'!