0

I am writing a program that uses a circular array to hold the int values and was just wondering if it was possible to use a linear search to find the lowest number in the circular array. I have used linear search before on 1d and 2d arrays but this is the first time i have used a circular array.

Thanks !!

  • It really would be better (and less offtopic) if you showed the code you have so far, no matter what it looks like. – TheBlastOne Apr 03 '14 at 13:24

2 Answers2

2

Searching a cyclical array should be the same as a 1d array. The only difference is your starting and ending points.

For a 1d array, your search is probably something like this:

for (int i=0; i<array.length; i++) ...

For a cyclical array, the search should stop when you return to your starting element.

Trenin
  • 2,041
  • 1
  • 14
  • 20
  • +1 for being the first one to mention the (though obvious) concept of stopping the search when the first element visited is visited again. – TheBlastOne Apr 03 '14 at 13:24
1

All you have to do is cycle through all the elements and remember the smallest value you found (and maybe its index). So, yes, it is possible!

Christian
  • 1,589
  • 1
  • 18
  • 36