10 תשובות
א.
public class car{
string id;
string car_model;
int yearofmanufacture;
string color;
}
ב לא למדתי מחסניות בjava אני לא יודע כלכך איך זה עובד שם
היי, עדיין רלוונטי?
שואל השאלה:
כן עדיין רלוונטי
אנונימית
*יאי*

אז הגדרתי מחלקה car בשביל א' (יש גם בנאי כדי שיהיה נוח לבדוק את זה אחר כך):

public class car
{
public int id;
public string model;
public int manufacturingyear;
public string color;

public car(int id, string model, int manufacturingyear, string color)
{
this.id = id;
this.model = model;
this.manufacturingyear = manufacturingyear;
this.color = color;
}
}
ואזז

את זה בשביל הסעיף השני

public static int getoldestcar(stack<car> stack)
{
stack<car> tempstack = new stack<car>();
car tempcar;
car oldestcar = stack.pop();
tempstack.push(oldestcar);

while (!stack.isempty())
{
tempcar = stack.pop();
tempstack.push(tempcar);

if (tempcar.manufacturingyear < oldestcar.manufacturingyear)
oldestcar = tempcar;
}

// restore original stack (just in case...)
while (!tempstack.isempty())
stack.push(tempstack.pop());

return oldestcar.id;
}
}
שואל השאלה:
יש תודהה
אנונימית
יפהה דולפין
אוי זה מחק לי חלק

בדקתי את זה טיפה אבל הייתי מציע לנסות כמה מצבי קיצון - ובכללי לעבור על המתודה לראות שהיא מתנהגת כמו שמצופה בשאלה