H-SC COMS 262 - Lecture 39 - The STL Applications

Unformatted text preview:

An STL ApplicationAssignmentThe Standard Template Library ApplicationsLecture 39Section 10.5Robb T. KoetherHampden-Sydney CollegeMon, Apr 26, 2010Robb T. Koether (Hampden-Sydney College) The Standard Template Library Applications Mon, Apr 26, 2010 1 / 9Outline1An STL Application2AssignmentRobb T. Koether (Hampden-Sydney College) The Standard Template Library Applications Mon, Apr 26, 2010 2 / 9Outline1An STL Application2AssignmentRobb T. Koether (Hampden-Sydney College) The Standard Template Library Applications Mon, Apr 26, 2010 3 / 9Convex HullThe convex hull program is somewhat simpler if we use the STLvector class.That is because of the additional member functions of the vectorclass.A ConvexHull object consists of a vector of points:vector<Point2D<int> > list;Robb T. Koether (Hampden-Sydney College) The Standard Template Library Applications Mon, Apr 26, 2010 4 / 9The ConvexHull ConstructorExample (The ConvexHull Constructor)ConvexHull(const vector<Point2D<int> >& pts){if (pts.size() < 3)list.insert(list.begin(), pts.begin(),pts.end());else{list.insert(list.begin(), pts.begin(),pts.begin() + 3);if (!hasPosOrient())reverse(list.begin(), list.end());for (int i = 3; i < pts.size(); i++)insert(pts[i]);}return;}Robb T. Koether (Hampden-Sydney College) The Standard Template Library Applications Mon, Apr 26, 2010 5 / 9The insert FunctionExample (The insert Function)void insert(const Point2D<int>& pt){if (!isInsideHull(pt)){int i = 0;while (!isLeftOfLine(i, pt))i = nextVertex(i);while (isLeftOfLine(i, pt))i = nextVertex(i);int k = i;while (!isLeftOfLine(i, pt))i = nextVertex(i);int m = i;...Robb T. Koether (Hampden-Sydney College) The Standard Template Library Applications Mon, Apr 26, 2010 6 / 9The insert FunctionExample (The insert Function)...if (m > k){list.erase(list.begin() + k + 1,list.begin() + m);list.insert(list.begin() + k + 1, pt);}else{list.erase(list.begin() + k + 1, list.end());list.erase(list.begin(), list.begin() + m);list.insert(list.begin(), pt);}}return;}Robb T. Koether (Hampden-Sydney College) The Standard Template Library Applications Mon, Apr 26, 2010 7 / 9Outline1An STL Application2AssignmentRobb T. Koether (Hampden-Sydney College) The Standard Template Library Applications Mon, Apr 26, 2010 8 / 9AssignmentHomewor kRead Section 10.5, pages 564 - 573.Robb T. Koether (Hampden-Sydney College) The Standard Template Library Applications Mon, Apr 26, 2010 9 /


View Full Document

H-SC COMS 262 - Lecture 39 - The STL Applications

Download Lecture 39 - The STL Applications
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 39 - The STL Applications and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 39 - The STL Applications 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?