Charlie's P3-Simulation has several good examples of using OrderedCollections to manage data structures.
initialize
super initialize.
statistics := Histogram from: 5 to: 70 by: 5.
route := OrderedCollection new.
busQueue := OrderedCollection new.
peopleQueue := OrderedCollection new.
first, addFirst:, and removeLast, it's pretty easy to create queues with data structures.
enqueue: aPerson
"Put a person in line."
peopleQueue addLast: aPerson.
dequeue: aroute
"removes the first occurence of a person in the queue that is in the current route"
| person head|
peopleQueue isEmpty
ifTrue:[ ^False ].
head := peopleQueue first.
[ aroute includes: (peopleQueue first event) ]
whileFalse: [
person := peopleQueue removeFirst.
peopleQueue addLast: person.
head == peopleQueue first
ifTrue: [ ^False ].
].
^peopleQueue removeFirst.
That latter search might be better performed with a detect: or select: method for OrderedCollections.
addTimeFrom: aPlace to: aDestination time: atime
"add a place and destination as well as the time that it takes to go between the two into
the route table"
| entry |
entry := OrderedCollection new.
entry add: aPlace.
entry add: aDestination.
entry add: atime.
route add: entry.