-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathASP.java
More file actions
67 lines (66 loc) · 1.67 KB
/
ASP.java
File metadata and controls
67 lines (66 loc) · 1.67 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.*;
import java.io.*;
public class ASP
{
static void swap (int a, int b)
{
int temp = a;
a = b;
b = temp;
}
static int partition (int a[], int s[], int low, int high)
{
int pivot = a[high];
int i=low-1;
for (int j=low;j<high;j++)
{
if (a[j] < pivot)
{
i++;
swap(a[i], a[j]);
swap(s[i], s[j]);
}
}
swap(a[i+1],a[high]);
swap(s[i+1],s[high]);
return i+1;
}
static void quicksort (int a[], int s[], int low, int high)
{
if (low < high)
{
int p = partition(a, s, low, high);
quicksort(a, s, low, p-1);
quicksort(a, s, p+1, high);
}
}
static void MaxActivities (int start[], int end[], int n)
{
quicksort(end, start, 0, end.length-1);
int i,j;
System.out.println("\nActivities Selected : ");
i=0;
System.out.print(i + " ");
for (j=1;j<n;j++)
{
if (start[j] >= end[i])
{
System.out.print(j + " ");
i = j;
}
}
System.out.println("");
}
public static void main(String args[])
{
Random rnd = new Random();
int start[] = new int[75];
int end[] = new int[75];
for (int i=0;i<start.length;i++)
{
start[i] = 1 + rnd.nextInt(94);
end[i] = start[i] + 1 + rnd.nextInt(6);
}
MaxActivities(start, end, start.length);
}
}