From d85ef17684ffc074e93805e6992bbfb4007976d2 Mon Sep 17 00:00:00 2001 From: rumata-ap Date: Thu, 30 Jul 2020 18:23:16 +0300 Subject: [PATCH] edit --- MatrixExtensions.csproj | 1 + MatrixL.cs | 118 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 MatrixL.cs diff --git a/MatrixExtensions.csproj b/MatrixExtensions.csproj index 8af398f..6314da9 100644 --- a/MatrixExtensions.csproj +++ b/MatrixExtensions.csproj @@ -72,6 +72,7 @@ + diff --git a/MatrixL.cs b/MatrixL.cs new file mode 100644 index 0000000..3864bcc --- /dev/null +++ b/MatrixL.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MatrixExtensions +{ + public class MatrixL + { + List> src; + T init; + int r; + int c; + + public MatrixL(int r, int c, T initValue) + { + this.r = r; + this.c = c; + init = initValue; + src = new List>(r); + for (int i = 0; i < r; i++) + { + src.Add(new List(c)); + for (int j = 0; j < c; j++) + { + src[i].Add(initValue); + } + } + } + + public T GetEl(int idxR, int idxC) + { + return src[idxR][idxC]; + } + + public void SetEl(int idxR, int idxC, T el) + { + src[idxR][idxC] = el; + } + + public void InsertRow(int idxR) + { + if (idxR > r) return; + + src.Insert(idxR, new List(c)); + r++; + for (int i = 0; i < c; i++) + { + src[idxR].Add(init); + } + } + + public void InsertRow(int idxR, List row) + { + if (idxR > r) return; + + src.Insert(idxR, new List(c)); + r++; + int n = c; + if (row.Count < c) n = row.Count; + + for (int i = 0; i < n; i++) + { + src[idxR].Add(row[i]); + } + + if (row.Count < c) + { + for (int i = n; i < c; i++) + { + src[idxR].Add(init); + } + } + } + + public void InsertCol(int idxC) + { + if (idxC > c) return; + + c++; + for (int i = 0; i < r; i++) + { + src[i].Insert(idxC, init); + } + } + + public void InsertCol(int idxC, List col) + { + if (idxC > c) return; + + c++; + for (int i = 0; i < r; i++) + { + src[i].Insert(idxC, init); + } + + int n = r; + if (col.Count < r) n = col.Count; + + foreach (List item in src) + { + for (int i = 0; i < n; i++) + { + item.Insert(idxC, col[i]); + } + if (col.Count < r) + { + for (int i = n; i < r; i++) + { + item.Insert(idxC, init); + } + } + } + } + + } +}