language_variants:
language_variants:
codeBlockMystery:
public static Node<int> Mystery (Node<int> chain)
{
Node<int> p = chain;
int x = p.GetValue();
while(p.GetNext() != null)
{
int y = p.GetNext().GetValue();
p.GetNext().SetValue(x);
x = y;
p = p.GetNext();
}
chain.SetValue(x);
return chain;
}
codeBlockMiracle:
public static Node<int> Miracle(Node<int> n)
{
Node<int> p = n;
while(p.GetNext() != null)
{
p = p.GetNext();
}
p.SetNext(n);
n = n.GetNext();
p = p.GetNext();
p.SetNext(null);
return n;
}
נתונה שרשרת חוליות הבאה: [10, 7, 14, 5, 7, 2, 4]. איך תיראה השרשרת אחרי זימון הפעולה mystery(chain)/Mystery(chain)? יש להראות מעקב אחרי ביצוע הפעולה.
exampleData: chainValues: [10, 7, 14, 5, 7, 2, 4]
נתונה שרשרת חוליות הבאה (אותם ערכים: [10, 7, 14, 5, 7, 2, 4]). אחרי זימון הפעולה miracle(n)/Miracle(n) התקבלה השרשרת הנתונה. איך נראתה השרשרת לפני זימון הפעולה?
exampleData: resultChainValues: [10, 7, 14, 5, 7, 2, 4]
note: this is a reverse-engineering question: the shown chain is the OUTPUT of miracle(n), student must derive the INPUT chain.
מה מבצעות הפעולות mystery(chain) ו-miracle(n) [Mystery/Miracle] כאשר הן מקבלות הפניות לחוליות הראשונות של שרשראות של מספרים שלמים?
שאלות ותגובות על השאלה
🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות
שאלו כאן — ותקבלו מענה מוסמך.