אתם מתרגלים שאלה מתוך מה"ט מבני נתונים ותכנות מונחה עצמים — הנדסאי תוכנהמבחן 2021 · קיץ מועד ב · שאלה 8כל שאלות המבחן ←
מבנים לינאריים›תורים

נתונות הפעולות secret, what ו-something:

public static int secret(Queue<Integer> q) {
    Queue<Integer> temp=new Queue<Integer>();
    while(!q.isEmpty()){
        temp.insert(q.remove());
    }
    int c=0;
    while(!temp.isEmpty()){
        c++;
        q.insert(temp.remove());
    }
    return c;
}
public static int what(Queue<Integer> q) {
    int len = secret(q);
    int temp = q.remove();
    q.insert(temp);
    for(int i = 0; i < len; i++){
        int curr = q.remove();
        q.insert(curr);
        if(curr > temp)
            temp = curr;
    }
    return temp;
}
public static boolean something(Queue<Integer> q1, Queue<Integer> q2) {
    if(secret(q1)==0)
        return false;
    int temp = what(q1);
    int len = secret(q2);
    for(int i = 0; i < len; i++){
        int curr = q2.remove();
        q2.insert(curr);
        if(temp <= curr)
            return false;
    }
    return true;
}

נתונים התורים הבאים:

a: 3, 1, 5, 1
b: 2, 1, 3, 1
c: 4, 4, 4
סעיף א

עקבו אחרי זימון הפעולה secret(a) ורשמו מה תהיה תוצאת הזימון.

סעיף ב

עקבו אחרי זימון הפעולה what(b) ורשמו מה תהיה תוצאת הזימון.

סעיף ג

עקבו אחרי זימון הפעולה something(a, c) ורשמו מה תהיה תוצאת הזימון.

סעיף ד

האם קיימים שני תורים q1, q2 כך ש-something(q1, q2) = something(q2, q1)? הסבירו.

סעיף ה

מה מבצעות הפעולות secret, what, something?

שאלות ותגובות על השאלה

🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות

שאלו כאן — ותקבלו מענה מוסמך.

🎓 מרצה לתכנות עונה כאן — תקבלו מענה מקצועי