beingtopper.jkp@gmail.com
+91-7529019575
Free Demo

Being Topper

  • Home
  • About Us
    • Founder’s Profile
    • Franchise
    • Women’s Entrepreneurship Development
  • Blog & Events
  • Modules
    • Website Planning and Creation
    • Social Media Marketing Course
    • Search Engine Optimization
    • SEM/PPC Training
  • Branches
    • Rajasthan
      • Ajmer
      • Jaipur
      • Jodhpur
      • Udaipur
      • Kota
      • Sikar
    • Janakpuri
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us

Being Topper

  • Home
  • About Us
    • Founder’s Profile
    • Franchise
    • Women’s Entrepreneurship Development
  • Blog & Events
  • Modules
    • Website Planning and Creation
    • Social Media Marketing Course
    • Search Engine Optimization
    • SEM/PPC Training
  • Branches
    • Rajasthan
      • Ajmer
      • Jaipur
      • Jodhpur
      • Udaipur
      • Kota
      • Sikar
    • Janakpuri
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us
  • Home
  • About Us
    • Founder’s Profile
    • Franchise
    • Women’s Entrepreneurship Development
  • Blog & Events
  • Modules
    • Website Planning and Creation
    • Social Media Marketing Course
    • Search Engine Optimization
    • SEM/PPC Training
  • Branches
    • Rajasthan
      • Ajmer
      • Jaipur
      • Jodhpur
      • Udaipur
      • Kota
      • Sikar
    • Janakpuri
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us

Being Topper

  • Home
  • About Us
    • Founder’s Profile
    • Franchise
    • Women’s Entrepreneurship Development
  • Blog & Events
  • Modules
    • Website Planning and Creation
    • Social Media Marketing Course
    • Search Engine Optimization
    • SEM/PPC Training
  • Branches
    • Rajasthan
      • Ajmer
      • Jaipur
      • Jodhpur
      • Udaipur
      • Kota
      • Sikar
    • Janakpuri
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us
Algorithm Design and analysis ProgramsB.tech notesBCA NOTESC++ programInformation technology

c++ program to perform breadth first search

Being Topper Admin 25/05/2013 0 Comments

WRITE A PROGRAM TO PERFORM BREADTH FIRST SEARCH

#include<iostream.h>
#include<conio.h>
#include<alloc.h>
struct queue
{ int data;
queue * next; };
queue * start=NULL;
queue * tail=NULL;
queue * ptr;
queue * temp;
void enqueue (int ver )
{ if (start==NULL)
{start=(queue*)malloc(sizeof(queue));
start->data=ver;
start->next=NULL;
tail=start;
temp=start; }
else
{ ptr=(queue*)malloc(sizeof(queue));
ptr->data=ver;
temp->next=ptr;
ptr->next=NULL;
tail=ptr; temp=ptr; } }
int dequeue ( )
{ int ver = start->data;
queue * temp1=start;
start=start->next;
free(temp1);
return ver; }
void main()
{ int adj[20][20],i,j,u,no_vertex,adjvertex,vertex[20],source,colour[20],dis[20],par[20];
char choice='y'; clrscr();
for(i=0;i<20;i++)
for(j=0;j<20;j++)
adj[i][j]=0;
cout<<"Enter the number of vertex in the graph<max 20>:";
cin>>no_vertex;
for(i=0;i<no_vertex;i++)
vertex[i]=i+1;
for(;i<20;i++)
vertex[i]=-1;
for(i=0;i<no_vertex;i++)
{cout<<"\nEnter the 1st adjacent vertex of vertex "<<i+1<<":";
cin>>adjvertex;
for(j=0;j!=adjvertex-1;j++) { }
adj[i][j]=1;
cout<<"\nAny other adjacent vertex?<y,n>:";
cin>>choice;
while(choice=='y')
{ cout<<"\nEnter the next adjacent vertex of vertex "<<i+1<<":";
cin>>adjvertex;
for(j=0;j!=adjvertex-1;j++)
{ }
adj[i][j]=1;
cout<<"\nAny other adjacent vertex?<y,n>:";
cin>>choice; }
}
cout<<"\nEnter the source of the graph<vertex number>:";
cin>>source; i=0;
while(vertex[i]!=-1)
{ colour[i]=0;
dis[i]=1000;
par[i]=-1; i++; }
colour[source-1]=1;
dis[source-1]= 0 ;
par[source-1]= -1 ;
enqueue ((source-1));
while (start!=NULL)
{ u=dequeue();
for(i=0;i<no_vertex;i++)
{ if(adj[u][i]==1)
{ if(colour[i]==0)
{ colour[i]=1;
dis[i]=dis[u]+1;
par[i]=u;
enqueue(i); } } }
colour[u]=2; }
cout<<endl;
for(i=0; vertex[i]!= -1 ;i++)
{ cout<<dis[i]<<" "; }
getch(); }

OUTPUT:

output for activity breadth first search

Algorithm and design analysis b.tech information technology notes BFS breadth first search c++ program to perform breadth first search c++ programs
AboutBeing Topper
"Being Topper, established in 2013, is a premier Digital Marketing Training institute Known for its specializing in digital marketing courses in Delhi. At Being Topper, our carefully crafted training programs are designed to offer learners the practical skills and knowledge essential for a thriving career in today's digital space. Led by certified professionals, the institute delivers top-rated courses that cover key areas, including Social Media Marketing, Pay-Per-Click advertising, content marketing and SEO. With hands-on projects and a focus on industry-specific practices, Being Topper prepares individuals to become effective digital marketing professionals, ready to excel in an increasingly digital-centric world
In Socials:
PrevC++ program to perform robin karp string matching25/05/2013
c++ program to perform naive string matching25/05/2013Next
Categories
Recent Posts
  • Vipin Khuttel Inspires Entrepreneurs at Networking Meet in Gurgaon
  • Vipin Khuttel Founder of Being Topper Recognized for Advancing Digital Literacy and Social Empowerment
  • Vipin Khuttel Organizes International Conference for Digital Excellence 2, Elevating the Future of Technology
  • India’s Top Occult Science Enthusiasts Gather at AgyatOnSearch – Awards & Seminar in New Delhi
  • India’s Leading Digital Marketer, Vipin Khuttel Interacted with Top Influencers of Delhi at BJP West Delhi’s Event

Copyright © 2025 Being Topper ® . All Rights Reserved