contract(g,u,v) --- contract v into u
All neighbors of v are added to the neighborhood of u,
and then v is deleted. (When v is deleted, vertices that have higher
index than v are renumbered.)
0001 function contract(g,u,v)
0002 % contract(g,u,v) --- contract v into u
0003 % All neighbors of v are added to the neighborhood of u,
0004 % and then v is deleted. (When v is deleted, vertices that have higher
0005 % index than v are renumbered.)
0006
0007 n = nv(g);
0008
0009 if (u<0) | (u>n) | (v<0) | (v>n) | (u==v)
0010 return
0011 end
0012
0013 nlist = neighbors(g,v);
0014
0015 for x = nlist;
0016 if (x ~= u)
0017 add(g,u,x)
0018 end
0019 end
0020
0021 delete(g,v);