注册 登录
编程论坛 闲聊灌水

每日灌水~

九转星河 发布于 2017-03-03 23:45, 56106 次点击
从忙碌的编程中解放出来~放松一下~休息~顺便灌水
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[此贴子已经被作者于2017-3-15 23:55编辑过]

768 回复
#302
九转星河2017-10-11 09:02
宜~乘胜追击~
#303
九转星河2017-10-12 13:53
宜~自我欣赏~
#304
九转星河2017-10-13 10:20
宜~相遇~
#305
九转星河2017-10-14 14:43
宜~息事宁人~
#306
九转星河2017-10-15 13:00
宜~考验~
#307
九转星河2017-10-16 08:13
宜~大度~
#308
九转星河2017-10-17 09:52
宜~买彩票~
#309
九转星河2017-10-18 08:11
宜~放空~
#310
九转星河2017-10-19 08:13
宜~攒人品~
#311
九转星河2017-10-20 07:37
宜~走心~
#312
九转星河2017-10-21 11:15
宜~远离尘嚣~
#313
九转星河2017-10-22 11:26
宜~走走停停~
#314
九转星河2017-10-23 09:34
宜~示爱~
#315
九转星河2017-10-24 07:34
宜~浪漫一场~
#316
九转星河2017-10-25 10:20
宜~期待~
#317
九转星河2017-10-26 08:12
宜~大度~
#318
九转星河2017-10-27 08:15
宜~独处~
#319
九转星河2017-10-28 10:42
宜~浪漫一场~
#320
九转星河2017-10-29 01:47
宜~磨蹭~
#321
a2968283612017-10-30 01:25
666
#322
九转星河2017-10-30 09:00
宜~追随~
#323
九转星河2017-10-31 06:56
宜~风风火火~
#324
九转星河2017-11-01 07:29
宜~扔东西~
#325
九转星河2017-11-02 05:33
宜~提要求~
#326
九转星河2017-11-03 10:03
宜~据理力争~
#327
九转星河2017-11-03 21:03
ungetc~
#328
九转星河2017-11-04 08:01
宜~邀约~
#329
九转星河2017-11-05 10:27
宜~带节奏~
#330
九转星河2017-11-06 07:36
宜~思考人生~
#331
九转星河2017-11-07 09:03
宜~珍重~
#332
九转星河2017-11-08 08:07
宜~沟通~
#333
九转星河2017-11-09 07:32
宜~自我欣赏~
#334
九转星河2017-11-11 07:00
宜~舒展身体~
#335
南方的雨2017-11-12 17:16
好久没有来了,想不到账号还能用
#336
九转星河2017-11-13 08:10
宜~冥想~
#337
九转星河2017-11-14 08:08
宜~借力~
#338
九转星河2017-11-15 08:27
宜~诗禅~
#339
九转星河2017-11-16 10:28
宜~煲剧~
#340
九转星河2017-11-17 12:03
宜~追随~
#341
九转星河2017-11-18 10:40
宜~拒绝~
#342
炎天2017-11-18 23:31
滴~特仑苏~
#343
九转星河2017-11-19 12:02
宜~思考人生~
#344
九转星河2017-11-20 09:03
宜~头脑风暴~
#345
九转星河2017-11-21 08:11
宜~享受~
#346
九转星河2017-11-22 07:43
宜~立盟约~
#347
九转星河2017-11-22 17:53
暂存上机代码,嗯,看来代码格式还可以美观一点~

程序代码:



//   稀疏矩阵的十字链表存储与输出。
#include <stdio.h>
#include <stdlib.h>
#define MaxRow    10
#define MaxCol    10


typedef int Etype;
typedef struct OLnode  {
    int i,j;                                  /* 行号、列号域 */
    Etype e;                                  /*  数据域      */
    struct OLnode *right,*down;       /* 行向的、列向的指针域 */
} OLnode;                            /* 数据元素结点类型  */

typedef struct {
    OLnode *rh[MaxRow],*ch[MaxCol];
    int mu,nu,tu;
}Crosslist;                       /* 十字链表行、列表头  */

/* 函数声明 */
void creatMatrix(Crosslist *M);
void out_M(Crosslist M);
void TransMatrix(Crosslist *a , Crosslist *b);

Crosslist ma,mb,mc; int z;

/*  主函数 */
int main(){

    creatMatrix(&ma);
    printf("\n     【创建的十字链接矩阵如下】\n");
    out_M(ma);
    TransMatrix(&ma , &mb);
    out_M(mb);

    TransMatrix(&mb,&mc);
    out_M(mc);

    return 0;
}  /* main */


/* 十字链表的输出  */
void out_M(Crosslist M) {
    int i; OLnode *p; //char ch;
   /*  输出矩阵的总行数、总列数、非零元素总个数 */
    printf("\n矩阵行数m=%d    列数n=%d   非0元素个数t=%d \n",M.mu,M.nu,M.tu);
    for(i=1; i<=M.mu; i++) {
        p=M.rh[i];         /*  指向第i行 */
        printf("  i=%d",i);
        if(p){
            while(p){
                printf("  (%3d%3d%4d) ",p->i,p->j,p->e);
                p=p->right;
            }
        }
        printf("\n");
    }
}


/* 创建十字链表      */
void creatMatrix(Crosslist *M) {
    int m,n,t,row,col,i,j;
    Etype va;  OLnode *p,*q,*s;
   
    /*  输入矩阵的总行数、总列数、非零元素总个数 */
    printf("\n  矩阵行数m,列数n,非零元素个数t(逗号隔开)=?");
    scanf("%d,%d,%d",&m,&n,&t);
    for(i=1; i<=m;i++) M->rh[i]=NULL;
    for(j=1; j<=n;j++) M->ch[j]=NULL;
    M->mu=m; M->nu=n; M->tu=t;   /*  建立成空十字链表  */
   
    /* 以下为非零元素的逐一输入和插入 */
    for(i=1;i<=M->tu;i++)
    {
        printf(" (0行列放弃,下标从1开始) 行号i,列号j,值e(逗号隔开)=?");
        scanf("%d,%d,%d",&row,&col,&va);
        p=(OLnode *)malloc(sizeof(OLnode));

        p->i=row;
        p->j=col;
        p->e=va;
        
        /*  在第row行上链接 */
        q=M->rh[row];
        s=q;
        while(q!=NULL && q->j < col)
        {
            s=q;
            q=q->right;
        }
        p->right=q;
        if(q==M->rh[row])  
            M->rh[row]=p;
        else
            s->right=p;

        /* 在第col列上链接    */
        q=M->ch[col];
        while(q && q->i  < row)
        {
            s=q;
            q=q->down;
        }

        p->down=q;
        if(q==M->ch[col])
            M->ch[col]=p;
        else
            s->down=p;
    } /* for */
}/* creatMatrix */


void TransMatrix(Crosslist *a , Crosslist *b)
{
    size_t i=0;
    OLnode* p=NULL;
    OLnode* q=NULL;
    OLnode* next=NULL;
    OLnode* row[MaxRow];

    b->mu=a->nu;
    b->nu=a->mu;
    b->tu=a->tu;

    for (i=1;i<=b->mu;++i)
    {
        b->ch[i]=NULL;
        row[i]=NULL;
    }
   
    for (i=0;i<=b->nu;++i)
        b->rh[i]=NULL;

    for (i=1;i<=a->mu;++i)
    {
    if ((q=a->rh[i])==NULL)
        continue;
   
    next=b->ch[i];
   
    while (q!=NULL)
    {
        int pMark=0;

        p=(OLnode* )malloc(sizeof(OLnode));

        if (p==NULL)
                exit(0);

            p->i=q->j;
            p->j=q->i;
            p->e=q->e;
            p->right=NULL;

        if (next!=NULL)
        next->down=p;
        else
        b->ch[i]=p;

        pMark=p->i;
        if (row[pMark]!=NULL)
        row[pMark]->right=p;
        else
        b->rh[pMark]=p;

        next=p;
        row[pMark]=p;
        p=p->down;
        q=q->right;
    }
   
    next->down=NULL;
    }
}




[此贴子已经被作者于2017-11-22 22:49编辑过]

#348
九转星河2017-11-23 08:08
宜~口直心快~
#349
九转星河2017-11-24 09:25
宜~装神秘~
#350
九转星河2017-11-25 08:20
宜~口直心快~
#351
九转星河2017-11-26 11:22
宜~示弱~
1234567891011.....1516