longest_cycle(p) -- return the length of the longest cycle in p where p is a permutation
0001 function maxlen = longest_cycle(p) 0002 % longest_cycle(p) -- return the length of the longest cycle in p 0003 % where p is a permutation 0004 0005 clist = cycles(p); 0006 maxlen = 0; 0007 for k=1:length(clist) 0008 len = length(clist{k}); 0009 if (len > maxlen) 0010 maxlen = len; 0011 end 0012 end