Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 14, 2021. It is now read-only.

Commit 422b950

Browse files
main-2 --> 9/10
1 parent c2023cb commit 422b950

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

‎Atv-13/Makefile‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
all:
22
gcc -g3 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -Wall -Werror -std=c99 -o main main.c -lm
3+
all2:
4+
gcc -g3 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -Wall -Werror -std=c99 -o main-2 main-2.c -lm
35
run:
4-
./main
6+
./main
7+
run2:
8+
./main-2

‎Atv-13/main‎

-14.3 KB
Binary file not shown.

‎Atv-13/main-2‎

92.5 KB
Binary file not shown.

‎Atv-13/main-2.c‎

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ void swapElements(point *vector, int i, int j){
1919
return;
2020
}
2121

22-
void quickSort(point *vector, int leftIndex, int rightIndex, intx){
22+
void quickSort(point *vector, int leftIndex, int rightIndex){
2323
if(leftIndex < rightIndex){
24-
float pivot = x ? vector[(int)((rightIndex+leftIndex)/2)].x : vector[(int)((rightIndex+leftIndex)/2)].y;
24+
float pivot = vector[(int)((rightIndex+leftIndex)/2)].x;
2525
int left = leftIndex, right = rightIndex;
2626

2727
while(1){
2828
// Selects elements from the left that are >= to the pivot
29-
while(x ? (vector[left].x < pivot) : (vector[left].y<pivot)){ left++; }
29+
while(vector[left].x < pivot){ left++; }
3030

3131
// Selects elements from the right that are <= to the pivot
32-
while(x ? (vector[right].x > pivot) : (vector[left].y>pivot)){ right--; }
32+
while(vector[right].x > pivot){ right--; }
3333

3434
// If the swapping the above selected elements is worth it, do it
3535
if(left < right){ swapElements(vector, left++, right--); } // And pass to the next element
@@ -40,8 +40,36 @@ void quickSort(point *vector, int leftIndex, int rightIndex, int x){
4040
}
4141

4242
// Sorts the partitions
43-
quickSort(vector, leftIndex, right, x);
44-
quickSort(vector, right+1, rightIndex, x);
43+
quickSort(vector, leftIndex, right);
44+
quickSort(vector, right+1, rightIndex);
45+
}
46+
47+
return;
48+
}
49+
50+
void quickSortY(point *vector, int leftIndex, int rightIndex){
51+
if(leftIndex < rightIndex){
52+
float pivot = vector[(int)((rightIndex+leftIndex)/2)].y;
53+
int left = leftIndex, right = rightIndex;
54+
55+
while(1){
56+
// Selects elements from the left that are >= to the pivot
57+
while(vector[left].y < pivot){ left++; }
58+
59+
// Selects elements from the right that are <= to the pivot
60+
while(vector[right].y > pivot){ right--; }
61+
62+
// If the swapping the above selected elements is worth it, do it
63+
if(left < right){ swapElements(vector, left++, right--); } // And pass to the next element
64+
65+
// If the swap is not worth it, the vector was successfully partitionted
66+
else{ break; }
67+
68+
}
69+
70+
// Sorts the partitions
71+
quickSort(vector, leftIndex, right);
72+
quickSort(vector, right+1, rightIndex);
4573
}
4674

4775
return;
@@ -70,19 +98,19 @@ float auxGetLowestDist(point *points, int leftIndex, int rightIndex){
7098
}
7199
}
72100

73-
quickSort(strip, 0, stripSize-1, 0);
101+
quickSortY(strip, 0, stripSize-1);
74102

75-
for(inti = 0; i<stripSize; i++){
76-
for(intj=i+1; j<stripSize&&(strip[j].y-strip[i].y<distance); j++){
77-
distance=min(distance, d(strip[i], strip[j]));
78-
}
79-
}
103+
floatdiv = (strip[0].x>points[leftIndex].x&&strip[stripSize-1].x<points[rightIndex].x)
104+
? auxGetLowestDist(strip, 0, stripSize-1)
105+
: -1;
106+
107+
free(strip);
80108

81-
return distance;
109+
return min(distance, div);
82110
}
83111

84112
float getLowestDist(point *points, int n){
85-
quickSort(points, 0, n-1, 1);
113+
quickSort(points, 0, n-1);
86114
return auxGetLowestDist(points, 0, n-1);
87115
}
88116

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /