http://users.metropolia.fi/~dangm/blog/?p=67で説明されている問題の解決策を実装しようとしています。私は c# 言語を初めて使用します。列挙子を使用して、特定の条件で辞書を反復処理したいと考えています。そのため、current と previous.current の 2 つの変数があり、辞書の最初の要素を指します。previous は辞書の前の要素を指します。辞書私はフォローのように繰り返しています
previous=current;
current.MoveNext();
問題は、辞書全体の前のポイントを辞書の最後の要素に、現在のポイントをランダムなキーと値のペア RawVariable(0,0) に初めて反復するときです。ディクショナリで、特定のキーまたは値を持つ要素を現在のポイントにする方法
ここに私のコードスニペットがあります
public void falling_disks(int[] A, int[] B)
{
Dictionary<int, int> filledDictionary = filldictionary(d1, A);
//previous stores the previous element in dictionary
var previous = filledDictionary .GetEnumerator();
//current stores next element of previous
var current = filledDictionary .GetEnumerator();
current.MoveNext();
//for each incoming element in array B
foreach (int ele in B)
{
//check if the current key is filled in hashtable h1 that is check if it
//is already added
if (!checkifthatvalueisfilled(current.Current.Key))
{
//if not check if current value is less than or equal to element
while ((current.Current.Value >= ele))
{
//assign previous to current
previous = current;
//move current to next position
current.MoveNext();
}
listofitemstoremove.Add(previous.Current.Key);
}
else
{
listofitemstoremove.Add(current.Current.Key);
}
foreach (int item in listofitemstoremove)
{
if (!(h1.ContainsKey(item)))
h1.Add(item, true);
}
}
Console.WriteLine(listofitemstoremove.Capacity);
}
public bool checkifthatvalueisfilled(int key)
{
if (h1.ContainsValue(h1.ContainsKey(key)) == true)
return true;
else return false;
}
}