MATLAB: Displaying a linked list as an array

arraylinked list

How would I display a linked list as an array of the values of every node in the list, in the order of which the list traverses? Ok, so let's say I have list structure with list.root as the index of the first node in the list. Each node has a value and a next pointer, indicating the index of the next node in the list. How would I show every value within the list structure as a single array of values?

Best Answer

Start an array with []. Start at list.root . Repeat {If the current list point is not the end of list, add list.value to the end of the array, and make list.next the current list point.}