疎行列(三元グループシーケンステーブル格納)6種類の動作の実現

3940 ワード

/*              
*   Copyright (c) 2015,                   
*   All rights reserved.
*         :     
*       :  2015   4   9  
*        :015

*    :      ,  10     
*   1:       ;
*   2:       ;
*   3:       ;
*   4:       ;
*   5:      ;
*   6:       ;


*    :
*   1.void CreateMatrix(Matrix &M);//    
*   2.void Output(Matrix M);//    
*   3.void TransposeMatrix1(Matrix &M);//      1
*   4.void TransposeMatrix2(Matrix &M);//      2
*   5.void TransposeMatrix3(Matrix &M);//      3
*   6.void AddMatrix(Matrix &M1,Matrix &M2);//    
*   7.void SubtractMatrix(Matrix &M1,Matrix &M2);//    
*   8.void MultiplyMatrix(Matrix &M,Matrix &N);//    
*   9.Status Check(Matrix M,int index,int row,int line);//    M   data  index       
*   10.void SortByRow(Matrix &M);//       
*   11.void SortByLine(Matrix &M);//       

*/
#include
#include
#include
#include
using namespace std;

#define OK 1
#define FALSE 0
#define MAXSIZE 10000

typedef int ElemType;
typedef int Status;

typedef struct
{
    int row;//        
    int line;//        
    ElemType elem;//      
} Triple;//          

typedef struct
{
    Triple data[MAXSIZE];//      
    int rownum;//     
    int linenum;//     
    int elemnum;//         
} Matrix;//    

void CreateMatrix(Matrix &M);//    
void Output(Matrix M);//    
void TransposeMatrix1(Matrix &M);//      1
void TransposeMatrix2(Matrix &M);//      2
void TransposeMatrix3(Matrix &M);//      3
void AddMatrix(Matrix &M1,Matrix &M2);//    
void SubtractMatrix(Matrix &M1,Matrix &M2);//    
void MultiplyMatrix(Matrix &M,Matrix &N);//    
Status Check(Matrix M,int index,int row,int line);//    M   data  index       
void SortByRow(Matrix &M);//       
void SortByLine(Matrix &M);//       
void Interaction();//    

int main()
{
    Interaction();

    Matrix M,N;
    int operate;
    while(cin>>operate)
    {
        switch(operate)
        {
        case 0:
            return 0;

        case 1:
            cout<>M.rownum>>M.linenum>>M.elemnum;
            CreateMatrix(M);
            break;

        case 2:
            Output(M);
            break;

        case 3:
            cout<>operate;

            switch(operate)
            {
            case 1:
                TransposeMatrix1(M);
                break;

            case 2:
                TransposeMatrix2(M);
                break;

            case 3:
                TransposeMatrix3(M);
                break;
            }
            break;

        case 4:
INPUT1:
            cout<>N.rownum>>N.linenum>>N.elemnum;
            if(M.rownum!=N.rownum||M.linenum!=N.linenum)
            {
                cout<>N.rownum>>N.linenum>>N.elemnum;
            if(M.rownum!=N.rownum||M.linenum!=N.linenum)
            {
                cout<>N.rownum>>N.linenum>>N.elemnum;
            if(M.linenum!=N.rownum)
            {
                cout<>M.data[i].row>>M.data[i].line>>M.data[i].elem;
    }

    SortByRow(M);//                      ,      
    cout<M.data[j].row||(M.data[i].row==M.data[j].row&&M.data[i].line>M.data[j].line))
                {
                    swap(M.data[i],M.data[j]);
                }
            }
        }
    }
}

void SortByLine(Matrix &M)//       
{
    if(M.elemnum)
    {
        for(int i=1; i<=M.elemnum; i++)
        {
            for(int j=i+1; j<=M.elemnum; j++)
            {
                if(M.data[i].line>M.data[j].line||(M.data[i].line==M.data[j].line&&M.data[i].row>M.data[j].row))
                {
                    swap(M.data[i],M.data[j]);
                }
            }
        }
    }
}

void Interaction()//    
{
    cout<