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

📄 linjiebiaobu.cpp

📁 关于数据结构的各章节的c原代码实现
💻 CPP
字号:
// linjiebiaobu.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
struct snode
{
 int vode;
 struct snode *next;
};

typedef struct snode* link;
struct snode head[6];
void creategraph(int *node,int num)
{
	link newnode,ptr;
	int from,to;
	for (int i=0;i<num;i++)
	{
      from=node[2*i];
	  to=node[2*i+1];
	  newnode=(link)malloc(sizeof(struct snode));
	  newnode->vode=to;
	  newnode->next=NULL;
	  ptr=&(head[from]);
	  while(ptr->next!=NULL)
		  ptr=ptr->next;
	  ptr->next=newnode;

	}
}

int main(int argc, char* argv[])
{   link ptr;
	int node[12][2]={{1,2},{2,1},{1,3},{3,1},{2,3},{3,2},{2,4},{4,2},{3,5},{5,3},{4,5},{5,4}};
    for(int i=1;i<6;i++)
	{
       head[i].vode=i;
	   head[i].next=NULL;

	}
   creategraph(node[0],12);
   printf("图的邻接矩阵内容:\n");
   for (i=1;i<6;i++)
   {   
	   printf("顶点%d==>",head[i].vode);
	   ptr=head[i].next;
	   while (ptr!=NULL)
	   {
		   printf("%d",ptr->vode);
		   ptr=ptr->next;

	   }
	   printf("\n");
   }
	return 0;
}

⌨️ 快捷键说明

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