language_variants:
language_variants:
codeBlockMystery:
public static Node<Integer> mystery (Node<Integer> chain)
{
Node<Integer> 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<Integer> miracle(Node<Integer> n)
{
Node<Integer> 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] כאשר הן מקבלות הפניות לחוליות הראשונות של שרשראות של מספרים שלמים?
שאלות ותגובות על השאלה
🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות
שאלו כאן — ותקבלו מענה מוסמך.