が経つにつれて、私はRで次のアルゴリズムを実装しようとしています:R:反復処理が一覧
Iterate(Cell: top)
While (top != null)
Print top.Value
top = top.Next
End While
End Iterate
基本的には、リスト与えられ、アルゴリズムは、リストがない場合でも、すぐに、それは「ヌル」をヒットとして破る必要があります以上。
myls<-list('africa','america south','asia','antarctica','australasia',NULL,'europe','america north')
は、私は()関数をis.null使用するためのforループを追加する必要がありましたが、次のコードは、災害であり、私はそれを修正するためにあなたの助けを必要としています。
Cell <- function(top) {
#This algorithm examines every cell in the linked list, so if the list contains N cells,
#it has run time O(N).
for (i in 1:length(top)){
while(is.null(top[[i]]) !=TRUE){
print(top)
top = next(top)
}
}
}
あなたは使用してこの機能を実行することがあります。
Cell(myls)
第2の解決策でのブレークの素晴らしい配置。素晴らしい仕事ヨハン、3つすべてを共有してくれてありがとう。 – Bhushan