• Post Reply Bookmark Topic Watch Topic
  • New Topic

changing head position of the circular array  RSS feed

 
Anissa Pary
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I have a method:

So if I have an array like
circularArray[0] = null;
circularArray[1] = null;
circularArray[2] = 7;
circularArray[3] = 1;
circularArray[4] = 16;
circularArray[5] = null;
I want my program to consider front to be 2. However, my implementation of the program does not let me do that? Can anyone help me please!
 
Jason Bullers
Ranch Hand
Posts: 115
11
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, for starters, you're going to have to keep a record of where your last insertion into the array was. The way your code is right now, you'll always be inserting at position 0. Give it another try where you are properly tracking (using a field) where your next insertion into the circular array will be, and see how that goes. I think that might help you see how to answer the question. It might also be helpful to draw out a picture and step through it.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can consider using the % and + operators together.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!