9 Replies - 892 Views - Last Post: 15 July 2012 - 09:20 PM Rate Topic: -----

#1 FastFox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 15-July 12

Ascending order without Array

Posted 15 July 2012 - 07:32 PM

Is there any sort of way or command in java that allows one to arrange a number of inputted doubles(in separate dialog boxes) from lowest to highest? This is without the use of arrays. I've been thinking about this and trying different way and i'm just completely stumped.

Also as a side question, can anyone recommend some sort of way where numbers inputted in different dialog boxes and what is returned is the highest and lowest numbers? The method i'm thinking of is using a loop. But I'm not just sure how to go about it. Currently I've done it the long way, separating min and max and using if statements for every number storing the max and min in separate variables. Anyway to make this more efficient without using arrays would be helpful.

if (N1 >= N2) {
            N1 = max
        } else  {
            N2 = max }
            	
       if (N2 >= N3) {
            N2 = max
        } else  {
            N3 = max }
   		
   		if (N3 >= N4) {
            N3 = max
        } else  {
            N4 = max }
   		
   		if (N4 >= N5) {
            N4 = max
        } else  {
            N5 = max }
   		
   		if (N5 >= N6) {
            N5 = max
        } else  {
            N6 = max }
   		
   		if (N6 >= N7) {
            N6 = max
        } else  {
            N7 = max }
            
      	if (N6 >= N7) {
            N6 = max
        } else  {
            N7 = max }
   		
   	    if (N7 >= N8) {
            N7 = max
        } else  {
            N8 = max }
   		
   		if (N8 >= N9) {
            N8 = max
        } else  {
            N9 = max }
   		
   		if (N9 >= N10) {
            N9 = max
        } else  {
            N10 = max }



Thanks a lot for your help.

Is This A Good Question/Topic? 0
  • +

Replies To: Ascending order without Array

#2 fromTheSprawl  Icon User is offline

  • Wandering Like A Fool
  • member icon

Reputation: 509
  • View blog
  • Posts: 2,041
  • Joined: 28-December 10

Re: Ascending order without Array

Posted 15 July 2012 - 07:35 PM

Without an array how would you hold all the doubles to compare them together? Or could you use other data structures?
Was This Post Helpful? 1
  • +
  • -

#3 FastFox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 15-July 12

Re: Ascending order without Array

Posted 15 July 2012 - 07:41 PM

View PostfromTheSprawl, on 15 July 2012 - 07:35 PM, said:

Without an array how would you hold all the doubles to compare them together? Or could you use other data structures?


I'm afraid not. I was thinking of doing it the looooooooooooooooooooooooong way of comparing each and every number to every other number and then storing the the highest as maxA, the second highest as maxB, third highest as maxC and so on and so forth all through if statements. But its a nightmare even thinking about doing so.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8032
  • View blog
  • Posts: 31,202
  • Joined: 06-March 08

Re: Ascending order without Array

Posted 15 July 2012 - 07:49 PM

You are allergic to array or what ?
Was This Post Helpful? 0
  • +
  • -

#5 FastFox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 15-July 12

Re: Ascending order without Array

Posted 15 July 2012 - 07:56 PM

View Postpbl, on 15 July 2012 - 07:49 PM, said:

You are allergic to array or what ?



lol, no, just not allowed use them for what I am working on. I've been trying my best to come up with different solutions but nothing has come so far.
Was This Post Helpful? 0
  • +
  • -

#6 FastFox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 15-July 12

Re: Ascending order without Array

Posted 15 July 2012 - 08:04 PM

Maybe some sort of loop that checks one value against all others, and then if its the highest puts the value in a separate variable1. And then compares a second value against all the others excluding the one in separate variable1, and if its the second highest puts it in separate Variable2? And this loop would rotate 12 times. So when it's it's done I can print out separate variable1 and separate variable etc etc all the way up until 12 and they'd be in order. Although this thought is all very theoretical right now I'm not sure if this approach is even possible.
Was This Post Helpful? 0
  • +
  • -

#7 fromTheSprawl  Icon User is offline

  • Wandering Like A Fool
  • member icon

Reputation: 509
  • View blog
  • Posts: 2,041
  • Joined: 28-December 10

Re: Ascending order without Array

Posted 15 July 2012 - 08:07 PM

View PostFastFox, on 16 July 2012 - 02:41 AM, said:

But its a nightmare even thinking about doing so.


Yes it is. Now, is there a static number of values you have to compare?
Was This Post Helpful? 1
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8032
  • View blog
  • Posts: 31,202
  • Joined: 06-March 08

Re: Ascending order without Array

Posted 15 July 2012 - 08:08 PM

View PostFastFox, on 15 July 2012 - 11:04 PM, said:

Maybe some sort of loop that checks one value against all others,

Looping on what if it is not an array index ? :)
Was This Post Helpful? 1
  • +
  • -

#9 FastFox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 15-July 12

Re: Ascending order without Array

Posted 15 July 2012 - 08:33 PM

View PostfromTheSprawl, on 15 July 2012 - 08:07 PM, said:

View PostFastFox, on 16 July 2012 - 02:41 AM, said:

But its a nightmare even thinking about doing so.


Yes it is. Now, is there a static number of values you have to compare?


It's user imputed so can be anything.


View Postpbl, on 15 July 2012 - 08:08 PM, said:

View PostFastFox, on 15 July 2012 - 11:04 PM, said:

Maybe some sort of loop that checks one value against all others,

Looping on what if it is not an array index ? :)


On the strings from the dialogue boxes that I've parced into doubles and assigned variables to

public class Tester4{
    
    public static void main(String[] args) {
    	
    	//variables dont forget semi collons through prigram
    	//change N1 to N1 and likewise teh rest cause thats what I did in calculations 
    	
    	double S1 = Double.parseDouble(m1);
    	double S2= Double.parseDouble(m2);
    	double S3= Double.parseDouble m3);
    	double S4= Double.parseDouble(m4);
        double S5= Double.parseDouble(m5);
        double S6= Double.parseDouble(m6);
        double S7= Double.parseDouble(m7);
    	double S8= Double.parseDouble(m8);
    	double s9= Double.parseDouble(m9);
    	double s10= Double.parseDouble(m10);
    									 		
    	
    		
    String m1 = javax.swing.JOptionPane.showInputDialog	("Please Enter mark of student 1");
   	String m2 = javax.swing.JOptionPane.showInputDialog	("Please Enter mark of student 2");
   	String m3 = javax.swing.JOptionPane.showInputDialog	("Please Enter mark of student 3");
   	String m4 = javax.swing.JOptionPane.showInputDialog	("Please Enter mark of student 4");
   	String m5 = javax.swing.JOptionPane.showInputDialog	("Please Enter mark of student 5");
    String m6 = javax.swing.JOptionPane.showInputDialog	("Please Enter mark of student 6");
   	String m7 = javax.swing.JOptionPane.showInputDialog	("Please Enter mark of student 7");
   	String m8 = javax.swing.JOptionPane.showInputDialog	("Please Enter mark of student 8");
   	String m9 = javax.swing.JOptionPane.showInputDialog	("Please Enter mark of student 9");
   	String m10 = javax.swing.JOptionPane.showInputDialog("Please Enter mark of student 10");

Was This Post Helpful? 0
  • +
  • -

#10 fromTheSprawl  Icon User is offline

  • Wandering Like A Fool
  • member icon

Reputation: 509
  • View blog
  • Posts: 2,041
  • Joined: 28-December 10

Re: Ascending order without Array

Posted 15 July 2012 - 09:20 PM

But you can't possibly take dynamic number of inputs then not use a data structure? Can you Sir pbl? For inputs, yeah, that is all well and good, and it is possible with a scenario where each input is compared to the last input, but going further than two inputs and comparing all of them without a data structure, I don't see how. Anyone?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1