Store all the elements in an Array Randomly and search in Java Data Structures
public class SearchArray { protected int[] values; SearchArray(int size){ values = new int[size]; for (int i=0; i<size; i++){ int randomNumber = (int)(Math.random()*size)+1; System.out.println(randomNumber); values[i] = randomNumber; }
}
public boolean searchNumberIterative(int number){ boolean status = false;for (int i=0; i<values.length; i++) { if (values[i] == number){status = true;break;} } return status;} |
Nice solution?
ReplyDelete