예제 #1
0
        static public void Run()
        {
            //Đọc đồ thị từ file, chuyển thành ma trận kề
            string             fileInputName = @"DanhSachKe.INP";
            List <List <int> > graph         = ReadGraph.Graph2AdjList(fileInputName);

            //Ghi file bậc đồ thị
            string       fileOutputName = @"DanhSachKe.OUT";
            StreamWriter sw             = new StreamWriter(fileOutputName);

            //In số đỉnh đồ thị
            sw.WriteLine(graph.Count);
            //In số bậc của từng đỉnh
            foreach (List <int> vertexList in graph)
            {
                int degree = 0; //số bậc của đỉnh
                foreach (int nameVertex in vertexList)
                {
                    degree++;
                }
                sw.Write(degree + " ");
            }

            sw.Close();
        }
예제 #2
0
        static public void Run()
        {
            //Đọc đồ thị từ file, chuyển thành ma trận kề
            string fileInputName = @"BacVaoRa.INP";

            int[,] graph = ReadGraph.Graph2AdjMatrix(fileInputName);

            //Ghi file bậc đồ thị
            string       fileOutputName = @"BacVaoRa.OUT";
            StreamWriter sw             = new StreamWriter(fileOutputName);

            //In số đỉnh đồ thị
            sw.WriteLine(graph.GetLength(0));
            //In số bậc vào và ra của từng đỉnh
            for (int i = 0; i < graph.GetLength(0); i++)
            {
                int degreeIn  = 0; //số bậc vào của đỉnh
                int degreeOut = 0; // số bậc ra của đỉnh
                for (int j = 0; j < graph.GetLength(1); j++)
                {
                    degreeIn  += graph[j, i];
                    degreeOut += graph[i, j];
                }
                sw.WriteLine(degreeIn + " " + degreeOut);
            }
            sw.Close();
        }
예제 #3
0
        static public void Run()
        {
            //Đọc đồ thị từ file, chuyển thành ma trận kề
            string fileInputName = @"BacDoThiVoHuong.INP";

            int[,] graph = ReadGraph.Graph2AdjMatrix(fileInputName);

            //Ghi file bậc đồ thị
            string       fileOutputName = @"BacDoThiVoHuong.OUT";
            StreamWriter sw             = new StreamWriter(fileOutputName);

            //In số đỉnh đồ thị
            sw.WriteLine(graph.GetLength(0));
            //In số bậc của từng đỉnh
            for (int i = 0; i < graph.GetLength(0); i++)
            {
                int degree = 0;// số bậc của đỉnh
                for (int j = 0; j < graph.GetLength(1); j++)
                {
                    degree += graph[i, j];
                }
                sw.Write(degree + " ");
            }
            sw.Close();
        }
예제 #4
0
        static public void Run()
        {
            //Đọc đồ thị từ file, chuyển thành ma trận kề
            string fileInputName           = @"DanhSachCanh.INP";
            List <Tuple <int, int> > graph = ReadGraph.Graph2AdjTupleList(fileInputName);

            //Ghi file bậc đồ thị
            string       fileOutputName = @"DanhSachCanh.OUT";
            StreamWriter sw             = new StreamWriter(fileOutputName);

            //In số đỉnh đồ thị và số bậc của từng đỉnh
            //foreach (Tuple<int ,int> arrisTuple in graph)
            //{
            //    int degree = 0; //số bậc của đỉnh
            //    foreach (int nameVertex in vertexList)
            //        degree++;
            //    sw.Write(degree + " ");
            //}

            sw.Close();
        }