נתונה הפעולה הבאה What, מה מבצעת הפעולה?
נתונה הפעולה הבאה What, מה מבצעת הפעולה?
namingAnomalyFlag: The method names
What/Whyare printed CAPITALIZED identically in BOTH the Java and the C# sections of this paper (contrast with every other question, e.g. Q1/Q2/Q3/Q6/Q7/Q11, where Java uses camelCase and C# uses PascalCase). Faithfully preserved as printed rather than silently normalized towhat/whyfor the Java side.
language_variants: codeBlock:
public static int What(Node<Integer> ch){
int c = 0;
while(ch != null)
{
c++;
ch = ch.getNext();
}
return c;
}
מה מבצעת הפעולה?
נתונה הפעולה Why המשתמשת בפעולה What, מה תחזיר הפעולה Why(ch1, ch2), עבור שתי שרשרות החוליות הבאות: יש להראות מעקב אחרי ביצוע הפעולה Why. אין צורך במעקב אחרי What.
codeBlock:
public static boolean Why(Node<Integer> ch1, Node<Integer> ch2) {
int len1 = What(ch1);
int len2 = What(ch2);
for(int i = 0; i < len1-len2; i++)
{
ch1 = ch1.getNext();
}
while(ch1!=null)
{
if(ch1.getValue() != ch2.getValue())
return false;
ch1 = ch1.getNext();
ch2 = ch2.getNext();
}
return true;
}
exampleFigure: descriptionHebrew: שתי שרשראות חוליות typeset, ערכים מפורשים בקוביות עם חצים בין הקוביות
ch1: [10, 7, 14, 5, 7, 2, 4]
ch2: [5, 7, 1, 4]
תנו דוגמה של שרשרת ch3 באורך ארבע חוליות, באופן שבו זימון הפעולה Why(ch1, ch3) יחזיר ערך שונה מזה שהוחזר בסעיף ב'.
תנו דוגמה של שרשרת ch4 באורך ארבע חוליות, באופן שבו זימון הפעולה Why(ch4, ch1) יחזיר ערך true. אם אי אפשר ליצור שרשרת כזאת, הסבירו למה.
מה מבצעות הפעולות Why(ch1,ch2) ו- What(ch) באופן כללי?
שאלות ותגובות על השאלה
🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות
שאלו כאן — ותקבלו מענה מוסמך.