namespace MST
{
class MST_C
{
public void main()
{
const int inf = 9999;
const int max = 60;
int[,] g = new int[max, max]; //初始化邻接矩阵
int n, e, i, j, k, v1, v2, weight;
Calculate myCalculate = new Calculate();
Adjacency myAdjacency = new Adjacency(); 应输入}
Output myOutput =new Output();
n = adjacency.adjacencyMatrix(int[,] g); 应输入;
myoutput.printg(int [,] g, n); 应输入; 另一个错误: 类、结构或接口成员声明中的标记“(”无效
myCalculate.prim(int[,] g, n); 应输入; 另一个错误: 类、结构或接口成员声明中的标记“(”无效
}
}
class Calculate
{
public void prim(int[,] g, int n)
{
int[] lowcost = new int[max];
int[] closet = new int[max];
int i, j, k, l, min;
Excel.ApplicationClass eApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
if (eApp == null)
{
return;
}
eApp.Visible = false;
Excel.Workbook eWb = eApp.Workbooks._Open(@"d:\line\Data.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Excel.Worksheet eWs = (Excel.Worksheet)eWb.Sheets[2];
Excel.Range ER = null;
ER = eWs.get_Range((object)"E1", Missing.Value);
ER.Value2 = "起始顶点";
ER.ColumnWidth = 12;
ER = eWs.get_Range((object)"F1", Missing.Value);
ER.Value2 = "结束顶点";
ER.ColumnWidth = 12;
ER = eWs.get_Range((object)"G1", Missing.Value);
ER.Value2 = "线路权值";
ER.ColumnWidth = 15;
eWs.get_Range("E1", "F1").Font.Bold = true;
eWs.get_Range("E1", "F1").VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
for (i = 2; i <= n; i++)
{
lowcost[i] = g[1, i];
closet[i] = 1;
}
lowcost[1] = 0;
for (i = 2; i <= n; i++)
{
min = inf;
k = 0;
for (j = 2; j <= n; j++)
if (lowcost[j] < min && lowcost[j] != 0)
{
min = lowcost[j];
k = j;
}
eApp.Cells[i, 5] = closet[k].ToString();
eApp.Cells[i, 6] = k.ToString();
eApp.Cells[i, 7] = min.ToString();
lowcost[k] = 0;
for (j = 2; j <= n; j++)
if (g[k, j] < lowcost[j]) //
{
lowcost[j] = g[k, j];
closet[j] = k;
}
}
eWb.SaveAs(@"d:\line\Data.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
eWb.Close(false, Missing.Value, Missing.Value);
eApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(ER);
System.Runtime.InteropServices.Marshal.ReleaseComObject(eWs);
System.Runtime.InteropServices.Marshal.ReleaseComObject(eWb);
System.Runtime.InteropServices.Marshal.ReleaseComObject(eApp);
GC.Collect(); //强制对零代到指定代进行垃圾回收
}
}
class Adjacency
{
public int adjacencyMatrix(int[,] g) //建立无向图
{
for (i = 1; i <= n; i++) //初始化矩阵,全部设为无穷大
for (j = 1; j <= n; j++)
g[i, j] = inf;
Excel.Application eApp = new Excel.Application();
Excel.Application eApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
eApp.Visible = false;
Excel.Workbook eWb = eApp.Workbooks._Open(@"d:\line\Data.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Excel.Worksheet eWs = (Excel.Worksheet)eApp.ActiveSheet; }
}
}
}
9 个解决方案
#1
你将你的代码缩进一下 你就会发现问题了
#2
排查吧,感觉是有其它非法字符
你只保留下面这段,看有哪些错误
namespace MST
{
class MST_C
{
public void main()
{
const int inf = 9999;
const int max = 60;
int[,] g = new int[max, max]; //初始化邻接矩阵
int n, e, i, j, k, v1, v2, weight;
Calculate myCalculate = new Calculate();
Adjacency myAdjacency = new Adjacency(); 应输入}
Output myOutput =new Output();
n = adjacency.adjacencyMatrix(int[,] g); 应输入;
myoutput.printg(int [,] g, n); 应输入; 另一个错误: 类、结构或接口成员声明中的标记“(”无效
myCalculate.prim(int[,] g, n); 应输入; 另一个错误: 类、结构或接口成员声明中的标记“(”无效
}
}
』
你只保留下面这段,看有哪些错误
namespace MST
{
class MST_C
{
public void main()
{
const int inf = 9999;
const int max = 60;
int[,] g = new int[max, max]; //初始化邻接矩阵
int n, e, i, j, k, v1, v2, weight;
Calculate myCalculate = new Calculate();
Adjacency myAdjacency = new Adjacency(); 应输入}
Output myOutput =new Output();
n = adjacency.adjacencyMatrix(int[,] g); 应输入;
myoutput.printg(int [,] g, n); 应输入; 另一个错误: 类、结构或接口成员声明中的标记“(”无效
myCalculate.prim(int[,] g, n); 应输入; 另一个错误: 类、结构或接口成员声明中的标记“(”无效
}
}
』
#3
有错的行,直接屏蔽掉,看错误是不是会消失
#4
我是一名初学者,自查了半天还没查出问题,请明示!
#5
写规范点,逐句排查,很容易就能找出来的。
#6
可是是贴代码的时候显得比较乱,下次我多加注意
#7
看着有点费劲
#8
查了一上午也没有查出来
#9
public void main()
{
const int inf = 9999;
const int max = 60;
int[,] g = new int[max, max]; //初始化邻接矩阵
int n, e, i, j, k, v1, v2, weight;
Calculate myCalculate = new Calculate();
Adjacency myAdjacency = new Adjacency();
Output myOutput =new Output();
n = adjAcency.adjacencyMatrix(int[,] g);
myOutput.printg(int [,] g ,int n);
myCalculate.prim(int [,] g, int n);
}
#1
你将你的代码缩进一下 你就会发现问题了
#2
排查吧,感觉是有其它非法字符
你只保留下面这段,看有哪些错误
namespace MST
{
class MST_C
{
public void main()
{
const int inf = 9999;
const int max = 60;
int[,] g = new int[max, max]; //初始化邻接矩阵
int n, e, i, j, k, v1, v2, weight;
Calculate myCalculate = new Calculate();
Adjacency myAdjacency = new Adjacency(); 应输入}
Output myOutput =new Output();
n = adjacency.adjacencyMatrix(int[,] g); 应输入;
myoutput.printg(int [,] g, n); 应输入; 另一个错误: 类、结构或接口成员声明中的标记“(”无效
myCalculate.prim(int[,] g, n); 应输入; 另一个错误: 类、结构或接口成员声明中的标记“(”无效
}
}
』
你只保留下面这段,看有哪些错误
namespace MST
{
class MST_C
{
public void main()
{
const int inf = 9999;
const int max = 60;
int[,] g = new int[max, max]; //初始化邻接矩阵
int n, e, i, j, k, v1, v2, weight;
Calculate myCalculate = new Calculate();
Adjacency myAdjacency = new Adjacency(); 应输入}
Output myOutput =new Output();
n = adjacency.adjacencyMatrix(int[,] g); 应输入;
myoutput.printg(int [,] g, n); 应输入; 另一个错误: 类、结构或接口成员声明中的标记“(”无效
myCalculate.prim(int[,] g, n); 应输入; 另一个错误: 类、结构或接口成员声明中的标记“(”无效
}
}
』
#3
有错的行,直接屏蔽掉,看错误是不是会消失
#4
我是一名初学者,自查了半天还没查出问题,请明示!
#5
写规范点,逐句排查,很容易就能找出来的。
#6
可是是贴代码的时候显得比较乱,下次我多加注意
#7
看着有点费劲
#8
查了一上午也没有查出来
#9
public void main()
{
const int inf = 9999;
const int max = 60;
int[,] g = new int[max, max]; //初始化邻接矩阵
int n, e, i, j, k, v1, v2, weight;
Calculate myCalculate = new Calculate();
Adjacency myAdjacency = new Adjacency();
Output myOutput =new Output();
n = adjAcency.adjacencyMatrix(int[,] g);
myOutput.printg(int [,] g ,int n);
myCalculate.prim(int [,] g, int n);
}