forked from dharmanshu1921/Daa-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.cpp
More file actions
86 lines (77 loc) · 1.95 KB
/
1.cpp
File metadata and controls
86 lines (77 loc) · 1.95 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.util.Scanner;
public class QuickSortInDescendingOrder
{
int arr[];
int len=0;
int i=0;
public void accept()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the Limit of the array:");
len=sc.nextInt();
arr=new int[len];
for(i=0;i< len;i++)
{
System.out.print("Enter the Number:");
arr[i]=sc.nextInt();
}
}
public int partition(int arr[],int lowerBound,int upperBound)
{
int pivot=arr[lowerBound];
int start=lowerBound;
int end=upperBound;
int temp=0;
while(start< end)
{
while(start< len && arr[start]>=pivot)
{
start++;
}
while(arr[end]< pivot)
{
end--;
}
if(start< end)
{
temp=arr[start];
arr[start]=arr[end];
arr[end]=temp;
}
else
{
temp=arr[lowerBound];
arr[lowerBound]=arr[end];
arr[end]=temp;
}
}
return end;
}
public void quickSort(int arr[],int lb,int ub)
{
if(lb< ub)
{
int location=partition(arr,lb,ub);
quickSort(arr,lb,location-1);
quickSort(arr,location+1,ub);
}
}
public void display()
{
for(i=0;i< len;i++)
{
System.out.print(arr[i]+" ");
}
System.out.println();
}
public static void main()
{
QuickSortInDescendingOrder ob1=new QuickSortInDescendingOrder();
ob1.accept();
System.out.println("Unsorted Array");
ob1.display();
ob1.quickSort(ob1.arr,0,ob1.len-1);
System.out.println("Sorted Array");
ob1.display();
}
}