⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sparsematrixasarray.cs

📁 Data Structures and Algorithms with Object-Oriented Design Patterns in C# 这本书的范例代码dll自己反编译的source
💻 CS
字号:
namespace Opus6
{
    using System;
    using System.Reflection;

    [Copyright("Copyright (c) 2001 by Bruno R. Preiss, P.Eng."), Version("$Id: SparseMatrixAsArray.cs,v 1.4 2001/10/28 19:50:09 brpreiss Exp $")]
    public class SparseMatrixAsArray : SparseMatrix
    {
        public SparseMatrixAsArray(int numberOfRows, int numberOfColumns, int fill)
        {
            this.numberOfRows = numberOfRows;
            this.numberOfColumns = numberOfColumns;
            this.fill = fill;
            this.values = new double[numberOfRows, fill];
            this.columns = new int[numberOfRows, fill];
            for (int num1 = 0; num1 < numberOfRows; num1++)
            {
                this.columns[num1, 0] = -1;
            }
        }

        private int FindPosition(int i, int j)
        {
            for (int num1 = 0; (num1 < this.fill) && (this.columns[i, num1] != -1); num1++)
            {
                if (this.columns[i, num1] == j)
                {
                    return num1;
                }
            }
            return -1;
        }

        public static void Main()
        {
            Matrix matrix1 = new SparseMatrixAsArray(6, 6, 3);
        }

        public override Matrix Plus(Matrix mat)
        {
            throw new MethodNotImplementedException();
        }

        public override void PutZero(int i, int j)
        {
            Bounds.Check(i, 0, this.numberOfRows);
            Bounds.Check(j, 0, this.numberOfColumns);
            int num1 = this.FindPosition(i, j);
            if (num1 >= 0)
            {
                int num2 = num1;
                while ((num2 < (this.numberOfColumns - 1)) && (this.columns[i, num2 + 1] != -1))
                {
                    this.values[i, num2] = this.values[i, num2 + 1];
                    this.columns[i, num2] = this.columns[i, num2 + 1];
                    num2++;
                }
                if (num2 < this.numberOfColumns)
                {
                    this.columns[i, num2] = -1;
                }
            }
        }

        public override Matrix Times(Matrix mat)
        {
            throw new MethodNotImplementedException();
        }


        public override int Columns
        {
            get
            {
                return this.numberOfColumns;
            }
        }

        public override double this[int i, int j]
        {
            get
            {
                Bounds.Check(i, 0, this.numberOfRows);
                Bounds.Check(j, 0, this.numberOfColumns);
                int num1 = this.FindPosition(i, j);
                if (num1 >= 0)
                {
                    return this.values[i, num1];
                }
                return 0;
            }
            set
            {
                Bounds.Check(i, 0, this.numberOfRows);
                Bounds.Check(j, 0, this.numberOfColumns);
                int num1 = this.FindPosition(i, j);
                if (num1 >= 0)
                {
                    this.values[i, num1] = value;
                }
                else
                {
                    int num2 = 0;
                    while ((num2 < this.fill) && (this.columns[i, num2] != -1))
                    {
                        num2++;
                    }
                    if (num2 >= this.fill)
                    {
                        throw new InvalidOperationException("row is full");
                    }
                    if (num2 < (this.fill - 1))
                    {
                        this.columns[i, num2 + 1] = -1;
                    }
                    while ((num2 > 0) && (this.columns[i, num2] >= j))
                    {
                        this.values[i, num2] = this.values[i, num2 - 1];
                        this.columns[i, num2] = this.columns[i, num2 - 1];
                        num2--;
                    }
                    this.values[i, num2] = value;
                    this.columns[i, num2] = j;
                }
            }
        }

        public override int Rows
        {
            get
            {
                return this.numberOfRows;
            }
        }

        public override Matrix Transpose
        {
            get
            {
                throw new MethodNotImplementedException();
            }
        }


        private int[,] columns;
        private const int END_OF_ROW = -1;
        private int fill;
        private int numberOfColumns;
        private int numberOfRows;
        private double[,] values;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -