Search Results

Search found 2 results on 1 pages for 'avrahamshuk'.

Page 1/1 | 1 

  • Efficient algorithm to find first available name

    - by Avrahamshuk
    I have an array containing names of items. I want to give the user the option to create items without specifying their name, so my program will have to supply a unique default name, like "Item 1". The challenge is that the name has to be unique so i have to check all the array for that default name, and if there is an item with the same name i have to change the name to be "Item 2" and so on until i find an available name. The obvious solution will be something like that: String name; for (int i = 0 , name = "Item " + i ; !isAvailable(name) ; i++); My problem with that algorithm is that it runs at O(N^2). I wonder if there is a known (or new) more efficient algorithm to solve this case. In other words my question is this: Is there any algorithm that finds the first greater-than-zero number that dose NOT exist in a given array, and runs at less that N^2? Thanks!

    Read the article

  • JList not showing items or showing selectively.

    - by Avrahamshuk
    I have a Java Swing application using a JList to show some data from a DB. I am using DefaulListModel as the data model for the list in this way: void PopulateSoldiersList() { try { soldiersListModel = new DefaultListModel(); for (Soldier i : myBackEnd.GetAllSoldiers()) { soldiersListModel.addElement(i); } this.listSoldiers.setModel(soldiersListModel); } catch (Exception ex) {// Error Message} } And for some reason, the list just stays empty... I even did make sure at runtime that all the data is set up properly in the data model and even in the "dataModel" property of the JList! In other place at the app i have a similar problem, but there, sometimes the list show few items from the model (but not all of them) I have no idea where to go from here... please help. Thanks!

    Read the article

1