程序填空题【只能填一个运算符(标识符、常量)】 要求输出: 5.5 using System; namespace FillBlanks1 { public struct TupNode < T > { public int r; public int c; public T d; }; public struct TSMatrix < T > { public int rows; public int cols; public int nums; public TupNode
[] data; }; public class SMatrixClass < T > { public TSMatrix
trip; public SMatrixClass( int rows, int cols) { trip = new TSMatrix
{ data = new TupNode
[100], rows = rows, cols = cols }; } public bool Setvalue( int i, int j, T x) { if (i < 0 || i >= trip.rows || j < 0 || j >= trip.cols) return false ; int k = 0; while (k < trip.nums && i > trip.data[k].r) k++; while (k < trip.nums && i == trip.data[k].r && j > trip.data[k].c) k++; if (trip.data[k].r == i && trip.data[k].c == j) trip.data[k].d = x; else { for ( int k1 = trip.nums - 1; k1 >= k; k1--) { trip.data[k1 + 1].r = trip.data[k1].r; trip.data[k1 + 1].c = trip.data[k1].c; trip.data[k1 + 1].d = trip.data[k1].d; } trip.data[k].r = i; trip.data[k].c = j; trip.data[k].d = x; trip.nums++; } return true ; } public bool GetValue( int i, int j, ref T x) { if (i < 0 || i >= trip.rows || j < 0 || j >= trip.cols) return false ; int k = 0; while (k < trip.nums && trip.data[k].r < i) k++; while (k < trip.nums && trip.data[k].r == i && trip.data[k].c < j) k++; if (trip.data[k].r == i && trip.data[k].c == j) x = trip.data[k].d; else x = default (T); return true ; } public SMatrixClass
Transpose() { var tb = new SMatrixClass
(trip.cols, trip.rows); tb.trip.rows = trip.cols; tb.trip.cols = trip.rows; tb.trip.nums = trip.nums; if (trip.nums != 0) { var q = 0; for ( int v = 0; v < trip.cols; v++) for ( int p = 0; p < trip.nums; p++) if (trip.data[p].c == v) { tb.trip.data[q].r = trip.data[p].c; tb.trip.data[q].c = trip.data[p].r; tb.trip.data[q].d = trip.data[p].d; q++; } } return tb; } } class Program { static void Main( string [] args) { var sMatrix = new SMatrixClass< double >(6, 6); sMatrix.Setvalue(1, 2, 5.5); sMatrix.Setvalue(3, 4, 6.7); var sMatrix2 = sMatrix.Transpose(); double x = 0; sMatrix2.GetValue( , ref x); Console.WriteLine(x.ToString()); } } }