נתונה מחלקה המתארת אבן דומינו (Domino):
נתונה מחלקה המתארת אבן דומינו (Domino):
language_variants: codeBlock:
public class Domino
{
private int left; // ערך מספרי צד שמאלי בין 0 ל-6 (כולל)
private int right; // ערך מספרי צד ימני בין 0 ל-6 (כולל)
public Domino(int left, int right)
{
this.left = left;
this.right = right;
}
}
extractionNote: the Domino class body is byte-identical between languages (int fields, same doc comments) — the only delta anywhere in this question is the method name casing on rotate/Rotate.
setGetNote: במחלקה הוגדרו פעולות set/get.
deckClass: descriptionHebrew: נתונה המחלקה Deck המתארת רשימת אבני דומינו:
language_variants: codeBlock:
public class Deck
{
private Node<Domino> head;
public Deck()
{
this.head = null;
}
}
wellOrderedRuleHebrew: רשימת אבני דומינו נקראת "מסודרת היטב" אם ערך של הצד הימני של כל אבן ברשימה (פרט לאבן האחרונה ברשימה) זהה לערך הצד השמאלי של האבן הבאה ברשימה. רשימה ריקה או רשימה שיש בה רק אבן אחת, היא רשימה "מסודרת היטב".
exampleFigure: descriptionHebrew: לדוגמה: הרשימה הבאה מוגדרת "מסודרת היטב" — head→[domino tile]→[domino tile]→[domino tile]→[domino tile]→null, tiles rendered as pip-pattern icons (not printed digits).
confidence: MEDIUM — the four domino tiles are drawn as small dice/pip-pattern graphics, not digitized text. Specific (left,right) pip values were not confidently countable from the rendered page at this resolution and are NOT asserted here; flagged for visual re-verification (zoom on the source PDF) before use as a solve-oracle input.
rotate()
כתבו במחלקה Domino את הפעולה rotate(). הפעולה מסובבת את האבן הנוכחית כלומר: מחליפים בין הערכים left ו-right.
כתבו במחלקה Deck פעולה הבודקת שרשימה שהיא בנתה שרשימה "מסודרת היטב". אם כן – הפעולה תחזיר ערך true, ולא – תחזיר ערך false.
כתבו במחלקה Deck פעולה המקבלת אבן דומינו ובודקת אם אפשר להוסיף אותה לרשימה כך שהיא תישאר "מסודרת היטב". אם כן – הפעולה תוסיף את האבן לרשימה ותחזיר ערך true, ולא – תחזיר ערך false. לדוגמה: אפשר להוסיף לרשימה שבדוגמה בסעיף א' את האבנים הבאות: (0,4), (1,1), (4,6). אי אפשר להוסיף את האבנים: (3,2), (5,6), (2,2).
שאלות ותגובות על השאלה
🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות
שאלו כאן — ותקבלו מענה מוסמך.