mirror of
https://github.com/rumata-ap/MatrixExtension_SMathStudio.git
synced 2026-01-12 03:49:47 +03:00
edit
This commit is contained in:
@@ -72,6 +72,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="MatrixExtensions.cs" />
|
<Compile Include="MatrixExtensions.cs" />
|
||||||
|
<Compile Include="MatrixL.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Utilites.cs" />
|
<Compile Include="Utilites.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
118
MatrixL.cs
Normal file
118
MatrixL.cs
Normal file
@@ -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<T>
|
||||||
|
{
|
||||||
|
List<List<T>> 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<List<T>>(r);
|
||||||
|
for (int i = 0; i < r; i++)
|
||||||
|
{
|
||||||
|
src.Add(new List<T>(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<T>(c));
|
||||||
|
r++;
|
||||||
|
for (int i = 0; i < c; i++)
|
||||||
|
{
|
||||||
|
src[idxR].Add(init);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InsertRow(int idxR, List<T> row)
|
||||||
|
{
|
||||||
|
if (idxR > r) return;
|
||||||
|
|
||||||
|
src.Insert(idxR, new List<T>(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<T> 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<T> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user