-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuick.java
More file actions
67 lines (61 loc) · 1.05 KB
/
Copy pathQuick.java
File metadata and controls
67 lines (61 loc) · 1.05 KB
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
import java.util.*;
class Quick
{
int i,j,t,pivot,c=0;
int partion(int a[],int st,int end)
{
pivot=a[st];
i=st;
j=end;
while(i<j)
{
while(++c>0 && pivot>=a[i]&&i<=end)
i++;
while(++c>0 && pivot<=a[j]&&j>st)
j--;
if(i<j)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
t=a[st];
a[st]=a[j];
a[j]=t;
}
return j;
}
void divide(int a[],int st,int end)
{
if(st<end)
{
j=partion(a,st,end);
divide(a,st,j-1);
divide(a,j+1,end);
}
}
}
class Naandhan
{
public static void main(String []srg)
{
Quick p=new Quick();
int n,c=0,i;
int a[]=new int[250];
Scanner d=new Scanner(System.in);
Random r=new Random();
n=d.nextInt();
for(i=0;i<n;i++)
a[i]=r.nextInt(1000);
for(i=0;i<n;i++)
System.out.println((i+1)+".-->"+a[i]);
long s=System.nanoTime();
p.divide(a,0,n-1);
long h=System.nanoTime();
System.out.println("Sorted Order:");
for(i=0;i<n;i++)
System.out.println(a[i]);
System.out.println("no of times execution:"+p.c);
System.out.println("Time Complexity:"+(h-s));
}
}