-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathclosest_pair.c
More file actions
99 lines (87 loc) · 1.78 KB
/
closest_pair.c
File metadata and controls
99 lines (87 loc) · 1.78 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
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<stdio.h>
#include<math.h>
void bubblesort(int arr[],int a,int b,int n)
{
int temp;
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1-i;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
}
int distance(int x1,int y1,int x2,int y2){
int d=sqrt(pow((x2-x1),2)+pow((y2-y1),2));
return d;
}
void closest(int a[],int b[],int n,int k){
int arr[n];
int brr[n];
for(int i=0;i<n-1;i++){
arr[i]= distnace(a[i],b[i],a[i+1],b[i+1]);
}
}
int main(){
int n;
printf("Enter the number of input pair:");
scanf("%d",&n);
int x[n],y[n];
for(int i=0;i<n;i++){
scanf("%d%d",&x[i],&y[i]);
}
int a[n],b[n]; //sorting in x
for(int i=0;i<n;i++){
a[i]=x[i];
b[i]=y[i];
}
int temp;
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
temp=b[j];
b[j]=b[j+1];
b[j+1]=temp;
}
}
}
for(int i=0;i<n;i++){
printf("(%d,%d) ",a[i],b[i]);
}
printf("\n");
int c[n],d[n]; //sorting in y
for(int i=0;i<n;i++){
c[i]=x[i];
d[i]=y[i];
}
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1-i;j++)
{
if(d[j]>d[j+1])
{
temp=c[j];
c[j]=c[j+1];
c[j+1]=temp;
temp=d[j];
d[j]=d[j+1];
d[j+1]=temp;
}
}
}
for(int i=0;i<n;i++){
printf("(%d,%d)",c[i],d[i]);
}
return 0;
}