Hello!
I have a code that is not complete, but a have an error when i call sort(v.begin(), v.end(), compare); (line 48)
the error says: too many arguments to funciton;
can somebody give me a clue about this?
#include <fstream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#define dmax 120000
usingnamespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
struct point {
double x,y;
};
vector <point> v(120000);
vector <point> hull(dmax);
int n;
double s;
//functions declaration
void read();
//reads the input file
double area(point x1, point x2);
// calculates the area of the triangle formed by the two points x1 & x2 with the origin O(0,0)
void first();
// replaces the first element form the vectorwith the first element from the left;
bool compare();
// compares the two polar angles
double polar(point p1);
// returnes the polar angle of the point p1
int main() {
read();
first();
// sort them by the polar angle
sort(v.begin(), v.end(), compare);
//browsing the vector and verifying the points
point a,b,c;
a=v[0];
b=v[1];
return 0;
}
void read() {
fin>>n;
for(int i=0; i<n; i++)
fin>>v[i].x>>v[i].y;
}
double area(point p1, point p2, point p3) {
return (p1.x*p2.y+p1.y*p3.x+p2.x*p3.y-p2.x*p1.y-p1.x*p3.y-p3.x*p2.y)/2;
}
bool compare(point p1, point p2) {
return (polar(p1)<polar(p2));
}
void first() {
point d;
int poz;
for(int i=0; i<n; i++){
if(v[i].x<d.x) {
d=v[i];
poz=i;
}
elseif(v[i].y>d.y) {
d=v[i];
poz=i;
}
}
v[poz]=v[0];
v[0]=d;
}
double polar(point p1) {
return p1.y/(sqrt(p1.y*p1.y+p1.x*p1.x));
}