You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Containers-Queue/CTQueue.class.st
+28-34
Original file line number
Diff line number
Diff line change
@@ -13,47 +13,27 @@ Class {
13
13
#category : #'Containers-Queue'
14
14
}
15
15
16
-
{ #category : #testing }
16
+
{ #category : #adding }
17
17
CTQueue>>add: anElement [
18
18
"Add an element to the receiver. Note that the addition makes sure that when iterating over the receiver added first element are accessed first."
19
19
20
20
elements addLast: anElement.
21
21
^ anElement
22
22
]
23
23
24
-
{ #category : #testing }
24
+
{ #category : #adding }
25
25
CTQueue>>addAll: aCollection [
26
26
"Add the elements contained in the argument to the receiver. Note that the addition makes sure that when iterating over the receiver added first element are accessed first."
27
27
28
28
elements addAllLast: aCollection.
29
29
^ aCollection
30
30
]
31
31
32
-
{ #category : #accessing }
33
-
CTQueue>>at: anIndex [
34
-
"Accessed the element to the given index in the receiver according to the adding order."
35
-
^ elements at: anIndex
36
-
]
37
-
38
-
{ #category : #'adding/removing' }
39
-
CTQueue>> dequeue [
40
-
"Return the older element of the receiver.."
41
-
42
-
^ elements removeFirst
43
-
]
44
-
45
-
{ #category : #'adding/removing' }
46
-
CTQueue>>dequeueIfNone: aBlock [
47
-
"Return the older element of the receiver.."
48
-
elements ifEmpty: [ aBlock value ].
49
-
^ elements removeFirst
50
-
]
51
-
52
32
{ #category : #iterating }
53
33
CTQueue>>do: aBlock [
54
34
"iterates the elements of the receiver starting first by first added elements."
55
35
56
-
selfdo: aBlock
36
+
elementsdo: aBlock
57
37
]
58
38
59
39
{ #category : #testing }
@@ -74,18 +54,32 @@ CTQueue >> isEmpty [
74
54
^ elements isEmpty
75
55
]
76
56
77
-
{ #category : #'adding/removing' }
78
-
CTQueue>>queue: anElement [
79
-
"Add an element to the receiver. Note that the addition makes sure that when iterating over the receiver added first element are accessed first."
57
+
{ #category : #removing }
58
+
CTQueue>>remove [
59
+
"Return the older element of the receiver.."
80
60
81
-
elements addLast: anElement.
82
-
^ anElement
61
+
^ elements ifEmpty: [ nil ] ifNotEmpty: [ elements removeFirst ].
83
62
]
84
63
85
-
{ #category : #'adding/removing' }
86
-
CTQueue>>queueAll: aCollection [
87
-
"Add the elements contained in the argument to the receiver. Note that the addition makes sure that when iterating over the receiver added first element are accessed first."
88
-
89
-
elements addAllLast: aCollection.
90
-
^ aCollection
64
+
{ #category : #removing }
65
+
CTQueue>>removeIfNone: aBlock [
66
+
"Return the older element of the receiver.."
67
+
elements ifEmpty: [ ^ aBlock value ].
68
+
^ elements removeFirst
91
69
]
70
+
71
+
{ #category : #removing }
72
+
CTQueue>> poll [
73
+
"Returns and removes the front element, or nil if empty."
74
+
^ elements ifEmpty: [ nil ] ifNotEmpty: [ elements removeFirst ].
75
+
]
76
+
77
+
{ #category : #accessing }
78
+
CTQueue>> peek [
79
+
^ elements ifEmpty: [ nil ] ifNotEmpty: [ elements first ].
0 commit comments