So, I would know how to sort it if I could use a vector, but we have to implement it using a list. Our professor said that we can use the sort function already implemented in the list class. If it were a vector, I could create a structure, and then use the sort from <algorithm> to go, although my list, but it will not allow me to use this, since std :: list does not have random access. The API says "template <class Compare>", but I donβt think it will help me.
I understand that I can use the sort function, but I need to use the item data to sort it. I sort the points by their polar angle, and I need to use the current Point, which is a member of my class as βoriginβ, so I cannot use the static comparison sorter, as usual.
EDIT I ββuse this as my sorting call: sortedList.sort(sorting);
and here is my function:
bool sorting(const Point& p, const Point& q) { Point z = pointStack.top(); Point u = Point(p.getX() - z.getX(), p.getY() - z.getY()); Point v = Point(q.getX() - z.getX(), q.getY() - z.getY()); double r = u.polarAngle(); double s = v.polarAngle(); if (r < s) { return true; } else { return false; } }
I keep getting
c: \ users \ wooly \ documents \ visual studio 2010 \ projects \ proj5 \ proj5 \ grahamscan.cpp (20): error C3867: 'GrahamScan :: sorting': list of calls to missing arguments; use '& GrahamScan :: sorting' to create a pointer to a member
since I need a top pointStack value to sort, but it is a member of my class.
source share