Graph wide search

Source: Internet
Author: User

/* Search for the image's breadth first */

# Include <stdlib. h>
# Define MAXQUEUE 10/* Maximum queue capacity */
Struct node/* Graphic Vertex Structure Announcement */
{
Int vertex;/* vertex data */
Struct node * nextnode;/* indicates the indicator of the next vertex */
};
Typedef struct node * graph;/* New graph structure State */
Struct node head [9];/* array of graph vertex structures */
Int visited [9];/* traverse record array */
Int queue [MAXQUEUE];/* queue array declaration */
Int front =-1;/* front-end of the queue */
Int rear =-1;/* backend of the queue */
/*----------------------------------------*/
/* Create a graph */
/*----------------------------------------*/
Void creategraph (int * node, int num)
{
Graph newnode;/* New vertex indicator */
Graph ptr;
Int from;/* the starting point of the Edge */
Int to;/* edge end */
Int I;
For (I = 0; I <num; I ++)/* read the Circuit of The Edge */
   {
From = node [I * 2];/* edge start point */
To = node [I * 2 + 1];/* edge end */
/* Create a new vertex memory */
Newnode = (graph) malloc (sizeof (struct node ));
Newnode-> vertex = to;/* create vertex content */
Newnode-> nextnode = NULL;/* set the initial value of the indicator */
Ptr = & (head [from]);/* vertex position */
While (ptr-> nextnode! = NULL)/* traverse to the end of the linked list */
Ptr = ptr-> nextnode;/* next vertex */
Ptr-> nextnode = newnode;/* insert end */
   }
}

</

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.