svp aide moi pour calculu la complexite de ce algorithme
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
 
public class hanoi {
	 static int s=1;
	 static int n;
	public static void hanoi(int n, String from, String temp, String to) {
	        if (n == 0)  return;
	          hanoi(n-1, from, to, temp);
	          System.out.println("Step "+(s++)+  " : Move the disc " + n + " from " + from + " to " + to );
	          hanoi(n-1, temp, from, to);
 
 
	    }
 
	    public static void main(String[] args) {
	    	JFrame f = new JFrame("Honoi");
	    	JPanel p = new JPanel();
	    	JPanel p1 = new JPanel();
	    	JPanel p2 = new JPanel();
	    	JPanel p3 = new JPanel();
	    	JPanel p4 = new JPanel();
	    	JPanel p5 = new JPanel();
	    	JLabel g1 = new JLabel("                                    how mach disc =");
	    	JLabel g = new JLabel("                                                       HONOI");
	    	JButton b = new JButton("OK");
	    	JButton b1 = new JButton("Quit");
	    	JTextField t = new JTextField();
	    	p.setLayout(new BorderLayout());
	    	p1.setLayout(new BorderLayout());
	    	p2.setLayout(new BorderLayout());
	    	p3.setLayout(new BorderLayout());
	    	p4.setLayout(new BorderLayout());
	    	p5.setLayout(new BorderLayout());
 
 
 
	    	p.add(g,BorderLayout.NORTH);  
	    	p.add(p2,BorderLayout.CENTER);
	    	p2.add(p5,BorderLayout.CENTER);
	    	p5.add(p1,BorderLayout.SOUTH);
	    	p1.add(g1,BorderLayout.CENTER);
	    	p1.add(t,BorderLayout.SOUTH);
	    	p.add(p3,BorderLayout.AFTER_LAST_LINE);
	    	p3.add(b1,BorderLayout.AFTER_LAST_LINE);
	    	p3.add(b);
 
	    	b.addMouseListener(new MouseAdapter(){
		    	   public void mouseClicked(MouseEvent e){
 
		    		   n=Integer.valueOf(t.getText());
		    		   hanoi(n, "A", "B", "C"); 
 
		    	   }
		    	}
		    		  );
	    	b1.addMouseListener(new MouseAdapter(){
		    	   public void mouseClicked(MouseEvent e){
		    		   System.exit(0);
		    	   }
		    	}
		    		  );
 
 
	    	f.setContentPane(p);
	    	f.setSize(400,200);
	    	f.setVisible(true);
 
	    }
}