Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Using the adjacency table method to create a graph. How to write the complete C code?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to write the complete C code for using the adjacency table method to create a graph. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

/ * the C code implementation of creating graph by adjacency table method of undirected graph * / # include # define MaxSize 20 / / maximum number of vertices of graph typedef char VertexType;// global variable, recording the number of vertices of graph int VertexNum;// defining graph vertex typedef struct GraphNode {VertexType ver; struct GraphNode * next;} GraphNode;// creating graph void CreateGraph (GraphNode * * g) {VertexType ch by adjacency table method / / used to receive vertex names int I = 0; GraphNode * p, * Q; (* g) = (GraphNode *) malloc (sizeof (GraphNode) * MaxSize); / / assign a structure array printf ("Please enter vertices of the graph:\ n") / / store vertices of the graph scanf ("% c", & ch); while ('\ n'! = ch) {(* g) [I]. Ver = ch; (* g) [I]. Next = NULL; igraphs; scanf ("% c", & ch) } VertexNum = I; / / record the number of vertices for (iDe0; iver); scanf ("% c", & ch); while ('\ n'! = ch) {p = (GraphNode *) malloc (sizeof (GraphNode)) P-> ver = ch; Q-> next = p; Q = p; Q-> next = NULL; scanf ("% c", & ch) Void PrintGraph (GraphNode * g) {GraphNode * p; printf ("the vertex of the graph is:\ n"); / / print vertex for (int iTun0; inext;} printf ("\ n");}} int main () {GraphNode * g) CreateGraph (& g); PrintGraph (g); return 0;}

Diagram of the test:

Test result

On the realization of using the adjacency table method to create a graph, how to write the complete C code is shared here. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report