HyperGraph

Details

diff --git a/HyperGraph/HyperGraph.csproj b/HyperGraph/HyperGraph.csproj
index 8ec65f9..25a2e26 100644
--- a/HyperGraph/HyperGraph.csproj
+++ b/HyperGraph/HyperGraph.csproj
@@ -41,6 +41,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Matrix.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>

HyperGraph/Matrix.cs 162(+158 -4)

diff --git a/HyperGraph/Matrix.cs b/HyperGraph/Matrix.cs
index 191cfbc..444756f 100644
--- a/HyperGraph/Matrix.cs
+++ b/HyperGraph/Matrix.cs
@@ -1,6 +1,4 @@
-using Microsoft.Analytics.Interfaces;
-using Microsoft.Analytics.Types.Sql;
-using System;
+using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
@@ -8,7 +6,163 @@ using System.Text;
 
 namespace HyperGraph
 {
-    class Matrix
+    class Matrix<T>
     {
+        public List<List<T>> matrix { get; }
+
+        public int countRow { get; private set; }
+
+        public int countColumn { get; private set; }
+
+        public Matrix()
+        {
+            matrix = new List<List<T>>();
+        }
+
+        public Matrix(int count, bool isColumn = false)
+        {
+            matrix = new List<List<T>>();
+            if (!isColumn)
+            {
+                countRow = 1;
+                countColumn = count;
+                matrix.Add(new List<T>());
+                for (int i = 0; i < count; i++)
+                    matrix[0].Add(default (T));                
+            }
+            else
+            {
+                countRow = count;
+                countColumn = 1;
+                for (int i = 0; i < count; i++)
+                {
+                    matrix.Add(new List<T>());
+                    matrix[i].Add(default(T));
+                }
+            }
+        }
+
+        public Matrix(int countR0w, int countCol)
+        {
+            matrix = new List<List<T>>();
+            countRow = countR0w;
+            countColumn = countCol;
+            for (int i = 0; i < countRow; i++)
+            {
+                matrix.Add(new List<T>());
+                for (int j = 0; j < countColumn; j++)
+                    matrix[i].Add(default(T));                
+            }            
+        }
+
+        public bool AddRow()
+        {
+            try
+            {
+                countRow++;
+                matrix.Add(new List<T>());
+                int i = matrix.Count - 1;
+                for (int j = 0; j < countColumn; j++)
+                    matrix[i].Add(default(T));
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e.Message);
+                return false;
+            }
+            return true;
+        }
+
+        public bool AddColumn()
+        {
+            try
+            {
+                countColumn++;
+                for (int i = 0; i < countRow; i++)
+                    matrix[i].Add(default(T));                 
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e.Message);
+                return false;
+            }
+            return true;
+        }
+
+        // Индексатор
+        public T this [int posRow, int posColumn]
+        {
+            get
+            {
+                try
+                {
+                    return matrix[posRow][posColumn];
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine(e.Message);
+                    return default(T);
+                }
+            }
+            set
+            {
+                try
+                {
+                    matrix[posRow][posColumn] = value;
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine(e.Message);                   
+                }
+            }
+
+        }
+        /// <summary>
+        /// Возвращает/Устанавливает List<typeparamref name="T"/>, содержащий строку (isColumn == false) или столбец (isColumn == true)
+        /// </summary>
+        /// <param name="pos">Номер обрабатываемого элемента</param>
+        /// <param name="isColumn">Обрабатывать столбец (true) или строку (false)</param>
+        /// <returns></returns>
+        public List<T> this [int pos, bool isColumn = false]
+        {
+            get
+            {
+                try
+                {
+                    if (!isColumn)
+                        return new List<T>(matrix[pos]);
+                    else
+                    {
+                        List<T> result = new List<T>();
+                        for (int i = 0; i < countRow; i++)
+                            result.Add(matrix[i][pos]);
+                        return result;
+                    }
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine(e.Message);
+                    return null;
+                }               
+            }
+            set
+            {
+                try
+                {
+                    if (!isColumn)
+                        matrix[pos] = new List<T>(value);
+                    else
+                    {
+                        List<T> input = new List<T>(value);
+                        for (int i = 0; i < countRow; i++)
+                            matrix[i][pos] = input[i];
+                    }
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine(e.Message);
+                }
+            }
+        }
     }
 }
\ No newline at end of file
diff --git a/HyperGraph/Program.cs b/HyperGraph/Program.cs
index 5220750..447c23f 100644
--- a/HyperGraph/Program.cs
+++ b/HyperGraph/Program.cs
@@ -10,6 +10,15 @@ namespace HyperGraph
     {
         static void Main(string[] args)
         {
+            Matrix<int> m = new Matrix<int>(4,5);
+            List<int> ex = m[0];
+            List<int> ex2 = m[2, true];
+
+            List<int> ex3 = new List<int>(); ex3.Add(4); ex3.Add(5); ex3.Add(6); ex3.Add(7); ex3.Add(8);
+            m[3] = ex3;
+            List<int> ex4 = m[3];          
+
+            Console.ReadKey();
         }
     }
 }