Your class can have an array member. For example:
class CarStack {
Car[] cars = new Car[7];
int top = 0;
void Push(Car c) {
if (top != cars.Length) {
cars[top++] = c;
}
}
Car Pop() {
if (top != 0) return cars[--top];
else return null;
}
}
And elsewhere in the program:
void CreateCarAndAddToStack(CarStack stack, String model, Color color)
{
Car c = new Car(model, color);
stack.Push(c);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…