• C++程序设计实践指导1.2二维数组的操作运算改写要求实现


    改写要求1:改写为以单链表表示二维数组

    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
        struct LinkNode
          {
                 int Row;
                 int Column;
                 int Data;
                 LinkNode *next;
                 };
    class MATRIX
    {
          int m;
          int sum;
      
                 
          public:
           struct LinkNode* creat(int x[][40],int k)
                 {
                            m=k;
                           LinkNode *pHead = new LinkNode;
                            pHead->next = NULL;
                            LinkNode* p = pHead;
                            for(int i=0;i<k;i++)
                            for(int j=0;j<k;j++)
                             {
                                LinkNode* pNewNode = new LinkNode;
                                pNewNode->Row = i;
                                pNewNode->Column = j;
                                pNewNode->Data = x[i][j];
                                pNewNode->next = NULL;
                                p->next = pNewNode;
                                p = pNewNode;
                             }
                            sum=0;
                            return pHead;
                 }
                              
                 void process(LinkNode* pHead);
                 void show(LinkNode* pHead)
                 {
                      int i=0;
                      LinkNode* p = pHead;
                      p=p->next;
                      while(p)
                      {                       
                      cout<<p->Data<<"	";
                      p=p->next;
                      i++;
                      if(i%4==0)
                      cout<<endl;
                      }
                      cout<<"sum="<<sum<<endl;
                 }
          };
    void MATRIX::process(LinkNode* pHead)
    {
            LinkNode* p = pHead;
            p=p->next;
            while(p)
            {
             if((p->Row==p->Column)||(p->Row+p->Column==m-1))
                       continue;
                       sum+=p->Data;
            } 
    }
    int main(int argc, char *argv[])
    {
        int b[40][40]={{1,1,1,1},{1,2,2,1},{1,2,2,1},{1,1,1,1}};
        LinkNode *pHead=new LinkNode;
        MATRIX mtx;
        pHead=mtx.creat(b,4);
        mtx.process(pHead);
        mtx.show(pHead);
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    

      

  • 相关阅读:
    hdu 1301 prime算法
    hdu 4763 kmp算法
    linux上安装程序出现的问题汇总
    linux之下载工具wget
    python之os模块
    管道和xargs的区别
    linux下查找文件或目录(which,whereis,locate,find)
    blast+学习之search tools
    linux的文件,目录操作命令(mv,rm,cp)
    PHPCMS V9 简单的二次开发
  • 原文地址:https://www.cnblogs.com/c5395348/p/4271910.html
Copyright © 2020-2023  润新知