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?

1 件のコメント

Jan
Jan 2013 年 3 月 4 日
There is a nearly infinite number of methods you could implement a linked list in Matlab. So how could we know the structure of your data? Please add any details by editing the question - not as answer or comment.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2013 年 3 月 6 日

0 投票

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.}

3 件のコメント

Joe
Joe 2013 年 3 月 8 日
So would I use a while loop as the current list point not equal to the end of the list as the condition?
Walter Roberson
Walter Roberson 2013 年 3 月 8 日
end-of-list marker rather than the last node, because you need to include the information from the last node.
Joe
Joe 2013 年 3 月 8 日
Okay I think I have it down, thank you for the help, very much appreciated!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by