Did you ever hear about Algorithms? The problem you explained is a classical
one. You can find more information about it on this website:

http://www.cut-the-knot.org/Curriculum/Combinatorics/JohnsonTrotter.shtml

Between the possible algorithms, the best one seems to be the
"Johnson-Trotter Algorithm (1962-1963)".
You can find a Java implementation of this algorithm here:

http://www.cs.princeton.edu/introcs/23recursion/JohnsonTrotter.java.html

I hope it could help you!

Bye,
Mike


        --------- Original Message --------
        Da: [email protected]
        To: [email protected]
<[email protected]>
        Oggetto: [java programming] Permutation
        Data: 30/01/09 21:58
        
        > 
> I want to perm all the numbers from 1 to 100;when i enter 1 as the
beggining  and 100 as the end it freezed my machine.I manage to let the
application accept only numbers that their range  will let the entry size
limit  to( the difference between the numbers<=20)so the machine can
proccess.Is there anyway to allow the application to perm numbers from1to
100?Some one should please run this application and try to rectify it to
perm numbers from 1 to 100 without freezing the machine...Also the perm
numbers will repeat numbers like (1,2) and(2,1)** * @(#)Perm.java * * *
@author  * @version 1.00 2009/1/30 */import javax.swing.JOptionPane;public
class Perm {   
>  public Perm() {    }    public static void main(String[] args){     int
Biggining=Integer.parseInt(JOptionPane.showInputDialog("Enter beggining
Value"));     int Ending=Integer.parseInt(JOptionPane.showInputDialog("Enter
End Value"));     boolean toobig =false;     int row=0;     int
col=0;             String msg ="Sorry the range is too big  cant do
that";        System.out.println("From  "+Biggining+" to "+Ending );        
for ( row=Biggining; row <= Ending; row++) {      for ( col=Biggining; col
<=Ending; col++) {               
>  if((Ending-Biggining)<21){            System.out.print(
"("+row+","+col+") "+" , " );}        else{              
toobig=true;        break;}       }      }            if(toobig){         
JOptionPane.showMessageDialog(null, msg);      }        //else{         
      }      }                        
>                                    
> 
> 
> 
>       
> > 
> 
> 
>  
 --
 Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP
autenticato? GRATIS solo con Email.it: http://www.email.it/f
 
 Sponsor:
 Blu American Express: gratuita a vita! 
 Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=8613&d=20090131



--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to