Example #1
0
        public string AddRoad(int c1, int c2, int d)
        {
            Road road = new Road();

            road.City1    = c1;
            road.City2    = c2;
            road.Distance = d;


            var sp1 = _CitiesList.CityRoads(road.City1);
            var sp2 = _CitiesList.CityRoads(road.City2);



            var rl1 = new RoadsList(_RoadsFile, road.City1, sp1);
            var rl2 = new RoadsList(_RoadsFile, road.City2, sp2);

            var p1 = rl1.AddRoad(road.City2, road.Distance, out sp1);



            rl2.UpdateLastRoadLink(p1);

            _CitiesList.UpdateRoadListPointer(road.City1, sp1);
            _CitiesList.UpdateRoadListPointer(road.City2, sp2 == RoadsList.EndOfList ? p1 : sp2);


            return("Road  was successfuly added!\n");
        }
Example #2
0
        public string DeleteRoad(int c1, int c2)
        {
            Road road = new Road();

            road.City1 = c1;
            road.City2 = c2;

            int offset1 = _CitiesList.CityRoads(road.City1);
            int offset2 = _CitiesList.CityRoads(road.City2);


            RoadsList rl1 = new RoadsList(_RoadsFile, road.City1, offset1);
            RoadsList rl2 = new RoadsList(_RoadsFile, road.City2, offset2);

            if (rl1.Delete(road.City2, out offset1) && rl2.Delete(road.City1, out offset2))
            {
                _CitiesList.UpdateRoadListPointer(road.City1, offset1);
                _CitiesList.UpdateRoadListPointer(road.City2, offset2);

                return("Road Deleted!\n");
            }


            return(":(\n");
        }