Notes
![]() ![]() Notes - notes.io |
#define MAX VERTICES 100
// Structure to represent a node in adjacency list struct Node I
int data;
struct Node next:
// Function to create a new node
struct Node createNode(int datal
struct Node newNode
(struct Node*)malloc(sizeof(struct Node)): newNode->data data; newNode->next NULL: return newNode;
// Function to add an edge to the graph void addEdgelstruct Node adjList], int u. int v)
53%
1
struct Node newlode createNode(v):
newNode: adjList[u]
newNode->next adjListful:
// Punction to perform Breadth First Search on a graph
// represented using adjacency list
void bfslstruct Node adjList[], int vertices.
int startNode, int visited[])
// Create a queue for BES
int queue(MAX_VERTICES]:
int front 0. rear 0:
// Mark the current node as visited and enqueue it
visited[startNode] = 1;
queue[rear startNode:
// Iterate over the queue
while (front reart {
// Dequeue a vertex from queue and print it
int current Node queue front++1:
printf("%d currentNode);
// Get all adjacent vertices of the dequeued Vertex
//currentNode If an adjacent has not been visited.
// then mark it visited and enqueue it
struct Node temp adjList [currentNode); while (temp 1 NULL) E
int neighbor temp->data:
if (!vinited[neighbor
visited[neighborl
1:
queue [rear
neighbor:
temp temp->next:
1
1
int main!)
// Number of vertices in the graph
int vertices 5:
// Adjacency list representation of the graph struct Node adjlist vertices): for (int i=0; 1 vertices; ++1)
adjList[i]
NULL;
// Add edges to the graph
addEdge(adjList, 0, 1);
addEdgeladjList. 0. 201
addEdge(adjList, 1, 31:
addEdge(adjList. 1, 4);
addEdgeladjList. 2, 4);
// Mark all the vertices as not visited
int visited[vertices):
for int 10:1 vertices) ++1)
visited[1] 0
// Perform BFS traversal starting from vertex 0
printf(
"Breadth First Traversal starting from vertex 0:1:
bis(adjList, vertices. O, visited);
return 0;
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team