Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So I've been working on my final project for c# And i need to create 3 classes with arrays one for cars One for StackArray And one for QueueArray. Only based on simple arrays (without usuing stack. Code) I have to give 7 cars with random colors beetween red and blue. Red for stackarray. And blue for queue array.

So I'm extra newbie to this...

The car class is easy so I've done it... now for stack and queque class... I created the stack class and now i need to create an array using my car constructor method and name it as a Stack array... Then i need to use next to give my first value to the stackarray in stack method of the stack class...

I think I explained it terribly but please help T-T this is the chart of my classes and methods i need to add for each. (Stack and queue method are constructor to give first value to it)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
288 views
Welcome To Ask or Share your Answers For Others

1 Answer

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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...