资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

c语言mrncy函数 c语言main函数用法

c语言 数据结构基本功能要求:

#include "stdio.h"

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册虚拟主机、营销软件、网站建设、柘荣网站维护、网站推广。

#define MAX 50

typedef struct LNode{

int data;

struct LNode *next;

}LNode;

void OutputDegree(int matrix[MAX][MAX], int n);

void Insert(LNode *head, int data);

void list(LNode *head);

void createAdjList(int matrix[MAX][MAX], int n, LNode *head[]);

void main()

{

int matrix1[MAX][MAX] = {{0,1,1},{1,0,1},{0,0,0}};

int matrix2[MAX][MAX] = {{0,1,0,1,0},{1,0,1,0,0},{0,1,0,1,1},{1,0,1,0,0},{0,0,1,0,0}};

int n; /* 顶点数 */

LNode *head[MAX];

int i;

n = 3;

printf("List degree of all vertex : \n");

OutputDegree(matrix1, n);

for(i=0; in; i++)

{

head[i] = (LNode *)malloc(sizeof(LNode));

head[i]-data = i+1;

}

createAdjList(matrix1, n, head);

printf("Adjancency List : \n");

for(i=0; in; i++)

{

printf("%d : ", head[i]-data);

list(head[i]);

printf("\n");

}

n = 5;

printf("List degree of all vertex : \n");

OutputDegree(matrix2, n);

for(i=0; in; i++)

{

head[i] = (LNode *)malloc(sizeof(LNode));

head[i]-data = i+1;

}

createAdjList(matrix2, n, head);

printf("Adjancency List : \n");

for(i=0; in; i++)

{

printf("%d : ", head[i]-data);

list(head[i]);

printf("\n");

}

}

/* 输出顶点的度 */

void OutputDegree(int matrix[MAX][MAX], int n)

{

int InDegree[MAX]; /* 入度 */

int OutDegree[MAX]; /* 出度 */

int i, j;

for(i=0; in; i++)

{

InDegree[i] = OutDegree[i] = 0;

for(j=0; jn; j++)

{

InDegree[i] += matrix[j][i];

OutDegree[i] += matrix[i][j];

}

}

for(i=0; in; i++)

{

printf("vertex %d : In - %d, Out - %d\n", i+1, InDegree[i], OutDegree[i]);

}

}

void Insert(LNode *head, int data)

{

LNode *pre = head-next;

LNode *temp;

temp = (LNode*)malloc(sizeof(LNode));

temp-data = data;

temp-next = NULL;

if(pre == NULL)

{

head-next = temp;

return;

}

for(; pre-next!=NULL; pre=pre-next);

pre-next = temp;

}

void list(LNode *head)

{

LNode *curr;

for(curr=head-next; curr!=NULL; curr=curr-next)

{

printf("%d\t", curr-data);

}

}

/* 根据邻接矩阵构建邻接表 */

void createAdjList(int matrix[MAX][MAX], int n, LNode *head[])

{

int i, j;

for(i=0; in; i++)

{

for(j=0; jn; j++)

{

if(matrix[i][j] != 0)

Insert(head[i], j+1);

}

}

}


新闻名称:c语言mrncy函数 c语言main函数用法
文章位置:http://cdkjz.cn/article/dosipid.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220