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

📄 ln12.c

📁 有关数据结构的一些例子。用C语言编写的。非常有价值的程序。对初学者有指导借鉴意义。
💻 C
字号:
#define NULL 0
#define maxsize 128
#include "stdio.h"
//#include "alloc.h"
typedef int datatype;

typedef struct
{ int i,j;
  datatype v;
} node;

typedef struct
{ int m,n,t;
  node data[maxsize];
} spmatrix;
spmatrix *S,*T,*p;

int d=1,e=1,c=1;

spmatrix *CREAT1()
{ int x,y,z,q;
  printf("\nBuild:\n");
  scanf("%d",&x);
  while(x!=NULL)
  { scanf("%d",&y);
	scanf("%d",&z);
	p->data[d].i=x;
	p->data[e].j=y;
	p->data[c].v=z;
	d++; e++; c++;
	scanf("%d",&x);
  }
	printf("Row\tLine\tData\n");
	for(q=1;q<=e-1;q++)
	 printf("%d\t%d\t%d\n",p->data[q].i,p->data[q].j,p->data[q].v);
  return(p);
}

spmatrix *TRANS(a)
spmatrix *a;
{ int ano,bno,col;
  spmatrix *b;
  printf("The new spmatrix is:\n");
  printf("Row\tLine\tData\n");
  b=(spmatrix *)malloc(sizeof(spmatrix));
  b->m=a->n;
  b->n=a->m;
  b->t=a->t;
  if(b->t>0)
  { bno=0;
    for(col=0;col<a->n;col++)
     for(ano=0;ano<a->t;ano++)
	  if(a->data[ano].j==col)
       { b->data[bno].i=a->data[ano].j;
		 b->data[bno].j=a->data[ano].i;
		 b->data[bno].v=a->data[ano].v;
		 bno++;
       }
  }
  return(b);
}

main()
{ int l;
  S=CREAT1();
  S->m=d; S->n=e; S->t=c;
  T=TRANS(S);
  for(l=0;l<=e-2;l++)
   printf("%d\t%d\t%d\n",T->data[l].i,T->data[l].j,T->data[l].v);
}

⌨️ 快捷键说明

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