function [E] = lostAtSeaCucumber(vec,name) n = []; [r,c] = size(vec) for i = 1:c n = [n,vec(i).Next]; end r(1) = n(1); for i = 2:length(n) r(end+1) = n(r(i-1)); end s = [1 r(1:length(n)-1)]; final = []; for i = 1:length(s) if ismember(vec(s(i)).Name,name) final = [final, vec(s(i)).Name,' ']; break end final = [final, vec(s(i)).Name,' '] end[E] = finalend
My code is messing up on this test case:
1×5 struct: (numbers are respective to the name above)
'Max' 'Cheyenne' 'Priyana' 'Beau' 'Gordon'
5 1 5 2 3
EDIT: the correct output should be 'Max Gordon Priyana Gordon' but I'm getting 'Max Gordon Priyana Gordon Priyana'
Best Answer