-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjava_code.java
80 lines (72 loc) · 1.14 KB
/
java_code.java
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
73
74
75
76
77
78
79
80
/*<applet code="selectionsortingapplet" width="1000" height="1000">
</applet>*/
import java.applet.*;
import java.awt.*;
public class selectionsortingapplet extends Applet implements Runnable
{
Thread t;
int ar[]={9, 22, 19, 14, 7, 6, 12, 25, 4, 11, 23, 16, 15, 8, 24, 13, 1, 5, 20, 17, 10, 21, 2, 3, 18};
int ipos=0,jpos=0,min=0;
public void init()
{
t=new Thread(this);
}
public void start()
{
t.start();
}
public void paint(Graphics g)
{
int x=0;
for (int i=0;i<=24;i++)
{
if (min==i)
{
g.setColor(Color.blue);
}
else if (ipos==i)
{
g.setColor(Color.red);
}
else if (jpos==i)
{
g.setColor(Color.green);
}
else
{
g.setColor(Color.black);
}
g.fillRect(100+x,100,20,10*ar[i]);
x+=30;
}
}
public void run()
{
for (int i=0;i<=23;i++)
{
min=i;
for (int j=i+1;j<=24;j++)
{
if (ar[min]>ar[j])
{
min=j;
}
ipos=i;
jpos=j;
repaint();
try
{
t.sleep(1000);
}
catch(Exception e){}
}
int temp=ar[i];
ar[i]=ar[min];
ar[min]=temp;
}
ipos=-1;
jpos=-1;
min=-1;
repaint();
}
}