סעיף א
נתונה הפעולה Why הבאה:
public static Node<int> Why(Node<int> chain, bool flag)
{
int count = 0;
Node<int> p = chain;
while(p != null)
{
int x = p.GetValue();
bool f = (x % 2 ==0);
if( f == flag)
count ++;
p = p.GetNext();
}
return new Node<int>(count);
}
נתונה שרשרת חוליות הבאה:
chain → 10 → 7 → 14 → 5 → 7 → 2 → 4
מה תחזיר הפעולה Why(chain, false)? יש להראות מעקב אחרי ביצוע הפעולה Why.
סעיף ב
נתונה הפעולה What הבאה:
public static void What(Node<int> chain)
{
Node<int> p = chain;
Node<int> temp;
while (p != null)
{
if(p.GetValue()%2 ==0)
temp = Why(p.GetNext(), false);
else
temp = Why(p.GetNext(), true);
temp.SetNext(p.GetNext());
p.SetNext(temp);
p = temp.GetNext();
}
}
עקבו אחרי ביצוע זימון הפעולה What(chain) ורשמו איך תראה השרשרת אחרי זימון הפעולה.
יש להראות מעקב אחרי ביצוע הפעולה What, אין צורך במעקב אחרי Why.
סעיף ג
מה מבצעות הפעולות What(chain) ו-Why(chain,flag) באופן כללי?
שאלות ותגובות על השאלה
🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות
שאלו כאן — ותקבלו מענה מוסמך.