资源简介

采用三元组表示稀疏矩阵,并定义矩阵的加、减、乘运算 正交链表表示稀疏矩阵

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SparseMatrix
{
    public partial class FmInput : Form
    {
        private Presenter _present;
        public FmInput(Presenter present)
        {
            InitializeComponent();
            _present = present;
        }

        public FmInput()
        {
            InitializeComponent();
        }



        private void btInput_Click(object sender EventArgs e)
        {
            if (_present.CurrentMatrix.RowNum * _present.CurrentMatrix.ColNum==0)
            {
                MessageBox.Show(“请先设置行数和列数“);
            }
            try {
                   if (_present.CurrentMatrix.IsOutofIndex())
                {
                       MessageBox.Show(“该矩阵非零元素过多,已不属于稀疏矩阵!“);
                }
                if (_present.AddItem(Convert.ToInt32(tbRowNum.Text) Convert.ToInt32(tbColNum.Text) (float)Convert.ToDouble(tbValue.Text))) {
                    tbValueNum.Text = _present.CurrentMatrix.Terms.ToString();
                    tbRatio.Text = _present.CurrentMatrix.Ratio.ToString();

                    ListViewItem newItem = new ListViewItem(new string[] { _present.CurrentMatrix.Terms.ToString() tbRowNum.Text tbColNum.Text tbValue.Text });

                    lvMatrix.Items.Add(newItem);
                    rTBMatrix.Text = _present.OutPutCurMetrix();
                }
            }
            catch 
            {
                MessageBox.Show(“请正确输入行数、列号和值!“);
                return;
            }
       
        }

        private void comboBox1_SelectedIndexChanged(object sender EventArgs e)
        {
            _present.SetCurrentMatrix(comboBox1.SelectedIndex + 1);

            Flash();
        }

        private void Flash()
        {
            rTBMatrix.Text = _present.OutPutCurMetrix();
            int i=1;
            lvMatrix.Items.Clear();
            foreach (Trituple node in _present.CurrentMatrix.TritupleExpress)
            {
                lvMatrix.Items.Add(new ListViewItem(new string[]{i.ToString()node.Row.ToString()node.Col.ToString()node.Value.ToString()}));
                i++;
            }

            tbValueNum.Text=_present.CurrentMatrix.Terms.ToString();
            tbValue.Text=““;
        }

        private void button1_Click(object sender EventArgs e)
        {
            int row;
            int col;
            try {
                row = Convert.ToInt32(tbRowNum.Text);
                col = Convert.ToInt32(tbColNum.Text); 
                _present.SetColAndRow(row col);

                lvMatrix.Items.Clear();

                rTBMatrix.Text = ““;
                tbRatio.Text = ““;
                tbValueNum.Text = ““;

            } catch {
                MessageBox.Show(“请正确输入行数和列数!“)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      10354  2010-06-21 23:45  SparseMatrix\SparseMatrix\Data\CrosslinkedList.cs

     文件       1862  2010-06-21 23:45  SparseMatrix\SparseMatrix\Data\CrosslinkedNode.cs

     文件      12498  2010-06-21 23:45  SparseMatrix\SparseMatrix\Data\SparseMatrix.cs

     文件        935  2010-06-21 23:45  SparseMatrix\SparseMatrix\Data\Trituple.cs

     文件       3186  2010-06-21 22:52  SparseMatrix\SparseMatrix\FmInput.cs

     文件      13647  2010-06-21 22:52  SparseMatrix\SparseMatrix\FmInput.Designer.cs

     文件       5814  2010-06-21 22:52  SparseMatrix\SparseMatrix\FmInput.resx

     文件       2760  2010-06-21 22:52  SparseMatrix\SparseMatrix\FmSparseMatrixCaculator.cs

     文件      11616  2010-06-21 22:52  SparseMatrix\SparseMatrix\FmSparseMatrixCaculator.Designer.cs

     文件       5814  2010-06-21 22:52  SparseMatrix\SparseMatrix\FmSparseMatrixCaculator.resx

     文件        398  2010-06-20 00:50  SparseMatrix\SparseMatrix\Form1.cs

     文件       5259  2010-06-20 00:50  SparseMatrix\SparseMatrix\Form1.Designer.cs

     文件       5814  2010-06-20 00:50  SparseMatrix\SparseMatrix\Form1.resx

     文件       3483  2010-06-21 23:45  SparseMatrix\SparseMatrix\Presenter.cs

     文件        511  2010-06-21 11:53  SparseMatrix\SparseMatrix\Program.cs

     文件       1368  2010-06-20 00:38  SparseMatrix\SparseMatrix\Properties\AssemblyInfo.cs

     文件       2857  2010-06-20 00:38  SparseMatrix\SparseMatrix\Properties\Resources.Designer.cs

     文件       5612  2010-06-20 00:38  SparseMatrix\SparseMatrix\Properties\Resources.resx

     文件       1097  2010-06-20 00:38  SparseMatrix\SparseMatrix\Properties\Settings.Designer.cs

     文件        249  2010-06-20 00:38  SparseMatrix\SparseMatrix\Properties\Settings.settings

     文件       4443  2010-06-21 23:45  SparseMatrix\SparseMatrix\SparseMatrix.csproj

     文件        260  2010-06-22 00:04  SparseMatrix\SparseMatrix.gpState

     文件        926  2010-06-20 00:38  SparseMatrix\SparseMatrix.sln

    ..A..H.     42496  2010-06-22 00:04  SparseMatrix\SparseMatrix.suo

     目录          0  2010-06-24 22:53  SparseMatrix\SparseMatrix\Data

     目录          0  2010-06-24 22:53  SparseMatrix\SparseMatrix\Properties

     目录          0  2010-06-24 22:53  SparseMatrix\SparseMatrix

     目录          0  2010-06-24 22:53  SparseMatrix

----------- ---------  ---------- -----  ----

               143259                    28

............此处省略1个文件信息

评论

共有 条评论