נתונות פעולות רקורסיביות Mystery ו-Secret:
נתונות פעולות רקורסיביות Mystery ו-Secret:
public static int Mystery(string s1, string s2)
{
if (s1.Length == 0 && s2.Length == 0) return 0;
if (s1.Length == 0) return -1;
if (s2.Length == 0) return 1;
if (s1[0] < s2[0]) return -1;
if (s1[0] > s2[0]) return 1;
return Mystery(s1.Substring(1), s2.Substring(1));
}
public static string[] Secret(string[] arr, string s)
{
string[] temp = new string[arr.Length];
SecretHelp(arr, temp, s, 0, 0, temp.Length - 1);
return temp;
}
private static void SecretHelp(string[] arr, string[] temp, string s, int i, int left, int right)
{
if (i < arr.Length)
{
if (Mystery(arr[i], s) < 0)
{
temp[left] = arr[i];
SecretHelp(arr, temp, s, i + 1, left + 1, right);
}
else
{
temp[right] = arr[i];
SecretHelp(arr, temp, s, i + 1, left, right - 1);
}
}
}
סעיף א
עקבו אחרי זימון Mystery("HELLO","HELP") ורשמו את תוצאת הזימון. יש להראות מעקב!
סעיף ב
מה מבצעת הפעולה Mystery(s1, s2) עבור שתי מחרוזות s1,s2?
סעיף ג
נתון מערך מחרוזות:
string[] arr = {"HELLO", "WORLD", "GOOD", "DAY","FOR","TEST"}
עקבו אחרי הזימון Secret(arr, "JAVA") ורשמו את תוצאות הזימון.
יש להראות מעקב אחרי הפעולה Secret, אין צורך במעקב אחרי הפעולה Mystery.
סעיף ד
מה מבצעת הפעולה Secret(arr, s) עבור מערך מחרוזות arr ומחרוזת s?
שאלות ותגובות על השאלה
🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות
שאלו כאן — ותקבלו מענה מוסמך.