コード例 #1
0
        public void insert(Donor d, PointLatLng r)
        {
            GeoCoordinate dis  = new GeoCoordinate();
            GeoCoordinate To   = new GeoCoordinate();
            GeoCoordinate newN = new GeoCoordinate(d.latlog.Lat, d.latlog.Lng);

            dis.Latitude  = r.Lat;
            dis.Longitude = r.Lng;
            node newnode = new node();

            newnode.data  = d;
            newnode.left  = null;
            newnode.right = null;
            node pp = null;
            node ptr;

            ptr = root;
            int xyz = 0;

            if (ptr == null)
            {
                if (dis.GetDistanceTo(newN) < 3000)
                {
                    root       = new node();
                    root.data  = newnode.data;
                    root.left  = null;
                    root.right = null;
                    length++;
                }
            }
            else
            {
                while (ptr != null)
                {
                    To.Latitude  = ptr.data.latlog.Lat;
                    To.Longitude = ptr.data.latlog.Lng;
                    if (dis.GetDistanceTo(newN) < 3000 && dis.GetDistanceTo(newN) < dis.GetDistanceTo(To))
                    {
                        pp  = ptr;
                        ptr = ptr.left;
                        xyz = 1;
                    }
                    else if (dis.GetDistanceTo(newN) < 3000)
                    {
                        pp  = ptr;
                        ptr = ptr.right;
                        xyz = 2;
                    }
                    else
                    {
                        xyz = 0;
                        break;
                    }
                }
                if (xyz == 1)
                {
                    pp.left       = new node();
                    pp.left.data  = newnode.data;
                    pp.left.left  = null;
                    pp.left.right = null;
                    ///MessageBox.Show("left inserted" + pp.left.data.blood_group);
                    length++;
                }
                else if (xyz == 2)
                {
                    pp.right      = new node();
                    pp.right.data = newnode.data;
                    pp.right.left = null;
                    pp.right.left = null;
                    ///MessageBox.Show("right inserted" + pp.right.data.blood_group);
                    length++;
                }
                else
                {
                }
            }
        }
コード例 #2
0
 public BST()
 {
     length = 0;
     root   = null;
 }