Package components.queue
Interface Queue<T>
- Type Parameters:
T
- type ofQueue
entries
- All Superinterfaces:
Iterable<T>
,QueueKernel<T>
,Standard<Queue<T>>
- All Known Implementing Classes:
Queue1L
,Queue2
,Queue3
,QueueSecondary
QueueKernel
enhanced with secondary methods.- Mathematical Definitions:
IS_TOTAL_PREORDER ( r: binary relation on T ) : boolean is for all x, y, z: T ((r(x, y) or r(y, x)) and (if (r(x, y) and r(y, z)) then r(x, z))) IS_SORTED ( s: string of T, r: binary relation on T ) : boolean is for all x, y: T where (<x, y> is substring of s) (r(x, y))
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Concatenates ("appends")q
to the end ofthis
.void
flip()
Reverses ("flips")this
.front()
Reports the front ofthis
.replaceFront
(T x) Replaces the front ofthis
withx
, and returns the old front.void
rotate
(int distance) Rotatesthis
.void
sort
(Comparator<T> order) Sortsthis
according to the ordering provided by thecompare
method fromorder
.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
Methods inherited from interface components.queue.QueueKernel
dequeue, enqueue, length
Methods inherited from interface components.standard.Standard
clear, newInstance, transferFrom
-
Method Details
-
front
Reports the front ofthis
.- Returns:
- the front entry of
this
- Aliases:
- reference returned by
front
- Requires:
this /= <>
- Ensures:
<front> is prefix of this
-
replaceFront
Replaces the front ofthis
withx
, and returns the old front.- Parameters:
x
- the new front entry- Returns:
- the old front entry
- Aliases:
- reference
x
- Updates:
this
- Requires:
this /= <>
- Ensures:
<replaceFront> is prefix of #this and this = <x> * #this[1, |#this|)
-
append
Concatenates ("appends")q
to the end ofthis
.- Parameters:
q
- theQueue
to be appended to the end ofthis
- Updates:
this
- Clears:
q
- Ensures:
this = #this * #q
-
flip
void flip()Reverses ("flips")this
.- Updates:
this
- Ensures:
this = rev(#this)
-
sort
Sortsthis
according to the ordering provided by thecompare
method fromorder
.- Parameters:
order
- ordering by which to sort- Updates:
this
- Requires:
IS_TOTAL_PREORDER([relation computed by order.compare method])
- Ensures:
perms(this, #this) and IS_SORTED(this, [relation computed by order.compare method])
-
rotate
Rotatesthis
.- Parameters:
distance
- distance by which to rotate- Updates:
this
- Ensures:
if #this = <> then this = #this else this = #this[distance mod |#this|, |#this|) * #this[0, distance mod |#this|)
-