Member Avatar for mrkm1188

Is there a way to improve the below Selection Sort code to make it more efficient?

int a, b, smallest, temp;
      for(a = 0; a < numIntegers - 1; a++)
      {
         smallest = a;;
         numComp++;
         for(b = a+1; b < numIntegers; b++)
         {
            if(Integer.parseInt(list[b].toString()) < Integer.parseInt(list[smallest].toString()))
            {
               smallest = b;
            }
            temp = Integer.parseInt(list[a].toString());
            list[a] = list[smallest];
            list[smallest] = temp;
            numSwaps++;
         }
      }
Member Avatar for hfx642

Well, for starters... If list is an array of integers, don't do...

Integer.parseInt(list[b].toString())
Member Avatar for mrkm1188

I mean in terms of the number of times it checks the if statement or the number of times it goes thru the for loops or swaps the items

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.