Professional Documents
Culture Documents
NguyenVanDucTinh 19DH110978
NguyenVanDucTinh 19DH110978
DSK_CH.txt
**********************************
7
1 3 2 18 5 15
2 12 3 2
3 7
0 6 4 3 5 8
0 9 5 4
6 2
2 4
********************************
DSK_VH.txt
*******************************
7
1 3 2 18 3 6 4 9 5 15
0 3 2 12 3 2
0 18 1 12 3 7 6 4
0 6 1 2 2 7 4 3 5 8
0 9 3 3 5 4
0 15 3 8 4 4 6 2
2 4 5 2
********************************
GraphDSK_TS.cs
********************************
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DucPhuong_B07
{
class GraphDSK_TS
{
// Cau truc cho do thi g co huong
LinkedList<Tuple<int, int>>[] v;
int n;
// C�c array l� bi?n to�n c?c ch? ph?c v? cho gi?i thu?t
int[] pre;
int[] dist;
bool[] processed;
//Propeties
public LinkedList<Tuple<int, int>>[] V
{
get { return v; }
set { v = value; }
}
// Contructor
public GraphDSK_TS() { }
public GraphDSK_TS(int k)
{
v = new LinkedList<Tuple<int, int>>[k];
n = k;
}
// Doc file ra ds ke co trong so
public void FileToDSK_TS(string filename)
{
StreamReader sr = new StreamReader(filename);
n = int.Parse(sr.ReadLine());
v = new LinkedList<Tuple<int, int>>[n];
}
}
**************************************************
Program.cs
*************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DucPhuong_B07
{
class Program
{
static int Menu()
{
int chon;
Console.WriteLine();
Console.WriteLine(" DIJSTRA - TIM DUONG DI NGAN NHAT");
Console.WriteLine(" 1. Tao do thi tu file");
Console.WriteLine(" 2. Xuat do thi DSK len man hinh");
Console.WriteLine(" 3. Duong di ngan nhat tu mot dinh den cac dinh con
lai");
Console.WriteLine(" 4. Duong di ngan nhat tu x den y");
Console.WriteLine(" 5. Duong di ngan nhat qua tu x den y qua dinh
trung gian z");
Console.WriteLine(" 6. Bai toan tim duong di ra bien");
Console.WriteLine(" 7. Chon thanh pho de hop");
Console.WriteLine(" 0. Thoat");
Console.Write(" Chon : ");
chon = int.Parse(Console.ReadLine());
Console.WriteLine(" **************************************");
return chon;
}
static void Main(string[] args)
{
GraphDSK_TS g = new GraphDSK_TS();
int chon;
do
{
chon = Menu();
Console.WriteLine();
switch (chon)
{
case 1: { g.FileToDSK_TS("../../TextFile/DSK_CH.txt"); break; }
case 2:
{
Console.WriteLine("Do thi DSK : ");
g.PrintDSK();
break;
}
case 3:
{
Console.WriteLine("Duong di ngan nhat tu dinh s den cac
dinh con lai : ");
Console.Write(" Nhap dinh s : ");
int s = int.Parse(Console.ReadLine());
g.Dijkstra(s);
Console.WriteLine();
break;
}
case 4:
{
Console.WriteLine("Tim duong di ngan nhat tu dinh x den
dinh y");
Console.Write(" Nhap dinh x : ");
int x = int.Parse(Console.ReadLine());
Console.Write(" Nhap dinh y : ");
int y = int.Parse(Console.ReadLine());
g.MinXY(x, y);
break;
}
case 5:
{
Console.WriteLine("Tim duong di ngan nhat tu dinh x den
dinh y qua dinh trung gian z");
Console.Write(" Nhap dinh x : ");
int x = int.Parse(Console.ReadLine());
Console.Write(" Nhap dinh y : ");
int y = int.Parse(Console.ReadLine());
Console.Write(" Nhap dinh z : ");
int z = int.Parse(Console.ReadLine());
g.MinXYZ(x, y, z);
break;
}
case 6:
{
Console.WriteLine(" BAI TOAN TIM DUONG RA BIEN");
//g.FileToMatran(); // Doc ma tran.txt -> ma tran ->
DSK
//g.DSKtoFile(); // dung tao file DSKrabien.txt
Console.WriteLine(" Nhap diem xuat phat : ");
Console.Write(" Nhap toa do x : ");
int x = int.Parse(Console.ReadLine());
Console.Write(" Nhap toa do y : ");
int y = int.Parse(Console.ReadLine());
int s = 6 * x + y; // Xac dinh dinh ruong ung
Console.WriteLine();
g.FileToDSK_TS("../../TextFile/DSKrabien.txt");
g.Dijkstra(s);
Console.WriteLine();
//g.Duongrabien(x, y);
break;
}
case 7:
{
Console.WriteLine(" BAI TOAN CHON THANH PHO DE
HOP");
GraphDSK_TS gtp = new GraphDSK_TS();
gtp.FileToDSK_TS("../../TextFile/DSK_VH.txt");
gtp.PrintDSK();
int tp;
tp = g.ChonThanhpho();
Console.WriteLine("Thanh pho duoc chon : " + tp);
break;
}
}
} while (chon != 0);
}
}
}