| edges used stack chosen pair |
edges := #((1 4) (1 2) (2 1) (1 3) (3 1)).
used := Array new: edges size withAll: false.
stack := OrderedCollection with: 1.
chosen := (1 to: edges size) detect: [:index |
 ((used at: index) not) and: [(edges at: index) includes: stack last]].
used at: chosen put: true.
pair := edges at: chosen.
stack add: (pair first = stack last ifTrue: [pair second] ifFalse: [pair first]).
{stack asArray. chosen. ((1 to: edges size) anySatisfy: [:index |
 ((used at: index) not) and: [(edges at: index) includes: stack last]])}
