ฉันกำลังพยายามใช้วิธีแก้ไขปัญหาตามที่อธิบายไว้ใน http://users.metropolia.fi/~dangm/blog/?p=67. ฉันยังใหม่กับภาษา c# ฉันต้องการวนซ้ำผ่านพจนานุกรมโดยใช้ตัวแจงนับและสำหรับเงื่อนไขเฉพาะ ดังนั้นจึงมีตัวแปรสองตัวที่เป็นปัจจุบันและก่อนหน้า ปัจจุบันชี้ไปที่องค์ประกอบแรกของพจนานุกรม ก่อนหน้าชี้ไปยังองค์ประกอบก่อนหน้าในพจนานุกรม ในขณะที่วนซ้ำ พจนานุกรม ฉันกำลังวนซ้ำเหมือนเดิม
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;
}
}
current
ไปที่จุดเริ่มต้นif (ele.Equals(b.Last())
? - person M.Babcock   schedule 07.03.2013Dictionary
หรือไม่ - person शेखर   schedule 07.03.2013