2 Replies - 418 Views - Last Post: 06 October 2012 - 11:13 PM Rate Topic: -----

#1 xonewingedangelx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 14-June 12

How to sort integers without an array list

Posted 06 October 2012 - 08:17 PM

In my program I have six different integers as counters so like a, b, c, d, e, f. I have buttons in my code that increase and decrease the value of the counters. I'm trying to display the highest value integer and 2nd highest value without the use of an array. If no integer have been increased, nothing should appear. If only one value has been increased, only the highest value should appear. If the highest value is tied with another value, the value that was previously higher will be the highest value.

So far, I tried doing it with this approach. !! NOT MY ACTUAL CODE MORE OF PSUEDO CODE.
int a, b, c ,d ,e ,f;
int firstPopular;
int secondPopular;
int thirdPopular; 
and so on.

if (a > firstPopular) {
firstPopular = a;
}

and on and on to F

then 

if (a < firstPopular) {
secondPopular =a;
}

and you know the rest.



However, this method doesn't work very well. Any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: How to sort integers without an array list

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10658
  • View blog
  • Posts: 39,571
  • Joined: 27-December 08

Re: How to sort integers without an array list

Posted 06 October 2012 - 08:56 PM

Serious question- why don't you want to use an array?
Was This Post Helpful? 1
  • +
  • -

#3 xonewingedangelx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 14-June 12

Re: How to sort integers without an array list

Posted 06 October 2012 - 11:13 PM

I ended up using an array and put each counter in and then sorted the array from least to greatest. then I used array.length -1 and array.length -2 in order to determine the top two most popular. However, now im stuck on what to do if the top two are tied in value.
Im using an if statement for the most popular
if (aCounter == highestNumber && aCounter != 0) {
"highestNumber is aCounter and display text"
}

if (bCounter == nexthighestNumber && isnt 0) {
"display text and next highest number is b counter"
}

what if statement should I do in order to fix my tie?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1