
   # define NIL 0
   # include<iostream.h>
   struct point {
      float x, y;
      struct point *prev, *next;
   };
   typedef struct point Type;
   class PointSet
   {
       private:
          Type* ptslist;
          float Area(float, float, float, float, float, float);
          void PrintList(Type *);
          void Scan(Type *);
          void Sort(Type *);
       public:
          PointSet() {ptslist = NIL;}
          void Insert(float a, float b);
          void ConvexHull();
   };

   void PointSet::Scan(Type* list)
   {
       Type *p=list, *p1=list, *p2, *p3;
       float temp;
       do {  p2 = p1->next;
             if (p2->next) p3 = p2->next;
             else p3 = p;
             temp = Area(p1->x, p1->y, p2->x,
                         p2->y, p3->x, p3->y);
             if (temp>=0.0) p1 = p1->next;
             // If p1,p2,p3 form a left turn
             // move one point ahead;
             // if not delete p2 and move back.
             else {
                p1->next=p3; p3->prev=p1; delete p2;
                p1 = p1->prev;
             }
       } while (!((p3 == p) && (temp>=0.0)));
   }

   void PointSet::ConvexHull()
   {
       // Find the point p in ptslist of lowest
       // x-coordinate. Sort the points according
       // to the angle made with p and x-axis.

       Sort(ptslist); Scan(ptslist); PrintList(ptslist);
   }

