-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram2.c
86 lines (74 loc) · 1.49 KB
/
program2.c
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
#include<stdio.h>
#include<stdlib.h>
void swap(int* a,int* b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void BubbleSort(int* arr,int low,int high)
{
for(int i=low;i<=high;i++)
{
for(int j=low;j<=high-i-1;j++)
{
if(arr[j] > arr[j+1])
swap(&arr[j],&arr[j+1]);
}
}
}
int Partition(int arr[],int low,int high)
{
int pivot = arr[high];
int i = low-1;
for(int j=low;j<high;j++)
{
if(arr[j] <= pivot)
{
++i;
swap(&arr[j],&arr[i]);
}
}
swap(&arr[i+1],&arr[high]);
return i+1;
}
void ModifiedQuickSort(int arr[],int low,int high)
{
if(low < high)
{
int q = Partition(arr,low,high);
if(high - low <= 30)
{
BubbleSort(arr,low,q-1);
BubbleSort(arr,q+1,high);
return;
}
else{
ModifiedQuickSort(arr,low,q-1);
ModifiedQuickSort(arr,q+1,high);
}
}
}
void main()
{
int arr[2000];
// for(int i=0;i<20;i++)
// {
// arr[i] = rand();
// }
for(int i=0;i<200;i++)
{
arr[i] = 2000-i;
}
for(int i=200;i<1000;i++)
{
arr[i] = i+1;
}
for(int i=1000;i<2000;i++)
{
arr[i] = i+123;
}
ModifiedQuickSort(arr,0,1999);
for(int i=0;i<2000;i++)
printf("%d ",arr[i]);
}