graph ← graph ##.popnode vertex ⍝ Pop vertex ⍵ to head of graph ⍺.
Returns a new graph with the indicated vertex moved to the front. The new graph
is functionally identical (isomorphic) to the original. This simple operation
can be used to accomplish any ordering of the graph's vertices.
Examples:
disp a ⍝ graph "a".
┌→──┬─┬───┬───┬─┐
│2 3│3│2 4│1 5│3│
└~─→┴─┴~─→┴~─→┴─┘
disp a popnode 2 ⍝ pop second node to front.
┌→┬───┬───┬───┬─┐
│3│1 3│1 4│2 5│3│
└─┴~─→┴~─→┴~─→┴─┘
disp a popnode 5 ⍝ pop fifth node to front.
┌→┬───┬─┬───┬───┐
│4│3 4│4│3 5│2 1│
└─┴~─→┴─┴~─→┴~─→┘
disp popnode a foldl ⍳⍴a ⍝ reverse graph using 5 pops.
┌→┬───┬───┬─┬───┐
│3│5 1│4 2│3│4 3│
└─┴~─→┴~─→┴─┴~─→┘
grot←{ ⍝ graph "rotation".
v←⍴⍺ ⍝ number of vertices.
rv←(v|-⍵)⍴v ⍝ (v v v) pops
a popnode foldl rv ⍝ rv pops of last vertex.
}
disp a grot 3 ⍝ 3-rotation of graph "a".
┌→──┬─┬───┬─┬───┐
│3 2│5│4 5│5│4 1│
└~─→┴─┴~─→┴─┴~─→┘
disp a grot ¯1 ⍝ ¯1-rotation of graph "a".
┌→┬───┬─┬───┬───┐
│4│3 4│4│3 5│2 1│
└─┴~─→┴─┴~─→┴~─→┘
See also: Graphs insnode remnode
Back to: contents
Back to: Dyalog APL
Trouble seeing APL font?