0

I need some sort of queue system in my game, trying to figure out the right way to go.

If I have a NSMutableArray, called customerQueue, and add 4 objects to that array. There will now be objects add index, [0],[1],[2],[3].

Then I wanna deal with customer number 1, that is index [0] in customerQueue. Since the customer is no longer in the queue, I can remove it from the array. So far so good.

However, now I want the remaining 3 objects in the queue to take a "step forward", like object at index [1] moves to index [0] and object at index [2] goes to [1]...,you get the point.

I can“t find a method in NSMutableArray.h for this, so, can it be done this way? Any similar approach?

marsrover
  • 715
  • 11
  • 27

2 Answers2

1

A category for NSMutableArray that turns it into a queue is explained here.

In your case all you really need to do is to remove the first object:

[customerQueue removeObjectAtIndex:0];
Community
  • 1
  • 1
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
0

This is done automatically when you remove the first element. You can never have an array which doesn't have the first index. When you remove the object at index 0, the object at index 1 automatically moves to index 0.

Sulthan
  • 128,090
  • 22
  • 218
  • 270