I have convex hull algorithm:
#include <cstdlib>
#include <iostream>
using namespace std;
typedef int point;
void convexhull(point x[],bool onedge ){
int N=sizeof(x)/sizeof(int);
int p=0;
bool used=new bool[N];
for (int i=1;i<N;i++){
if (x[i]<x[p])
p=i;
}
int start=p;
do
{
int n=-1;
int dist=onedge?32756:0;
for (int i=0;i<N;i++){
//dont go back to the same point you come from
if (i==p) continue;
if (used[i]) continue;
//if there is not such N yet,set it to x
if (n==-1) n=i;
int cross=(x[i]-x[p])*(x[n]-x[p]);
//d is distance from P to x
int d=(x[i]-x[p])*(x[i]-x[p]);
if (cross<0){
n=i;
dist=d;
}
else if (cross==0){
//in this case both N and X are4 in the
//same direction.if onedge is true
//pick the closest one,otherwidr pick farthest one
if (onedge && d<dist){
dist=d;
n=i;
}
else if (!onedge && d>dist)}
dist=d;
n=i;
}
}
}
p=n;
used[p]=true;
} while(start!=p);
}
int main(int argc, char *argv[])
{
system("PAUSE");
return EXIT_SUCCESS;
}
But when I compile it, it shows me errors like this:
26 G:\convex_hull.cpp invalid types `bool[int]' for array subscript
48 G:\convex_hull.cpp expected primary-expression before '}' token
67 G:\convex_hull.cpp expected `,' or `;' before '=' token
Please help me to understand what is wrong. Can’t I use integer subscripts with bool arrays?
Since you’re declaring a dynamically allocated array, you need a pointer:
You also have a bracket the other way around:
instead of
Btw, next time please take the time to properly indent your code.