public myMatrix <TColumn, TRow, TValue> Transpose() { myMatrix <TColumn, TRow, TValue> trans = new myMatrix <TColumn, TRow, TValue>(); foreach (TRow row in row_map.Keys) { foreach (TColumn col in col_map.Keys) { //transpose the matrix O(n**2) trans[col, row] = arr[row_map[row], col_map[col]]; } } return(trans); }
//transpose matrix public myMatrix <TColumn, TRow, TValue> Transpose() { myMatrix <TColumn, TRow, TValue> result = new myMatrix <TColumn, TRow, TValue>(); foreach (TRow row in row_map.Keys) { foreach (TColumn col in col_map.Keys) { try { result[col, row] = arr[row_map[row]][col_map[col]]; } catch (ArgumentOutOfRangeException) { } } } return(result); }
static void Main(string[] args) { //testing myMatrix <string, string, string> myIndexer = new myMatrix <string, string, string>(); myIndexer["1", "1"] = "22"; myIndexer["1", "2"] = "23"; myIndexer["2", "1"] = "44"; myIndexer["2", "2"] = "46"; myIndexer["3", "2"] = "55"; myIndexer.Print(); //Console.WriteLine(myIndexer["1", "2"]); myMatrix <string, string, string> trans = myIndexer.Transpose(); trans.Print(); myIndexer.RemoveRow("1"); myIndexer.Print(); myIndexer.RemoveCol("1"); myIndexer.Print(); }