BFS tree Code in C++

#include#includeint cost[10][10],i,j,k,n;int que[10],front,rare,v,visit[10],visited[10];void main(){clrscr();int m;cout <<"Enter no of vertices\ Nodes: ";cin >> n;cout <<"\nEnter no of Edges: ";cin >> m;cout <<"\n\tEnter All EDGES by source & destination\n";for(k=1;k<=m;k++){cout<<"\nEnter Source: ";cin >>i;cout<<"\nEnter Destination: ";cin>>j;cost[i][j]=1;cout<<"\n———————–\n";}cout <<"\nEnter initial vertex: ";cin >>v;cout <<"Visitied vertices:\n";cout << v<<" ";visited[v]=1;k=1;while(k<n){for(j=1;j<=n;j++)if(cost[v][j]!=0 && visited[j]!=1 && visit[j]!=1){visit[j]=1;que[rare++]=j;}v=que[front++];cout<<v << " ";k++;visit[v]=0;visited[v]=1;}getch();}

Circular D – Queue Using Arrays

Implementation of Circular D-Queue (Double-Ended-Queue) in C++ Using Classes and Arrays :—————————————————–Assignment Question ☺ ☺See Also:  Linear Double Ended Queue #include#includeclass d_queue{private:int rfront,rrear,lfront,lrear,max;int *queue;public:d_queue(){ clrscr();    lfront=lrear=-1;   cout<<"\n\n\tEnter the size of Queue: ";   cin>>max;   for(int z=0;z<=max;z++){queue[z]=0;}   rfront=max;rrear=max+1;   } void insert_left(int n){   if(lfront==-1 && lrear==-1)   { lfront=lrear=0;     queue[lrear]=n;   }   else if( queue[lrear+1]==0  &&  lrear+1!=rrear)   {Continue reading “Circular D – Queue Using Arrays”

Double-ended Queue in C++ Using Array

Implementation of Linear Double Ended Queue in C++ Using Arrays and ClassesAssignment Question ☺☺ See Also: Circular Double Ended Queue (circular D-Queue) #include#include#define Max 5class D_Queue{private:int front,rfront,rrear,rear,max;int d_queueary[Max];public:D_Queue(){clrscr();front=-1,rfront=0;rear=-1,rrear=0;//cout<<"\nEnter the size of D-Queue: ";//cin>>max;//d_queueary[max];}void insert_left(int n){ if(rear==max) cout<<"\n Sorry Queue is Full \n"; else rear=rear+1; d_queueary[rear]=n;}void delete_left(){ if(rear==-1) cout<<"\n Queue is Empty\n"; else cout<<"\nDeleted Value = "<<d_queueary[rear]; rear=rear-1;}void insert_right(intContinue reading “Double-ended Queue in C++ Using Array”

Priority Queue in C++

Implementation of  Priority Queue on the bases of Acceding Order in C++ Using Arrays and Classes Assignment Question: ☺☺☺ // copyright@2014 ☻ usman siddique //pcphunt.blogsopt.com #include#includeclass queue{private:int front,rear,max,i,temp;int *queuearr;public:queue(){cout<<"\nEnter the size of Queue: ";cin>>max;i=temp=0;front=0,rear=-1;int *Queue=new int[max];}void insert(int n){ if(rear==max) cout<<"\nQueue is full\n";else  {   rear=rear+1;   queuearr[rear]=n; if(queuearr[rear]<queuearr[rear-1])       //This part of code check it     Continue reading “Priority Queue in C++”

Implementation of linear Queue in C++

Implementation of single[two ended],(simple),linear Queue in C++ using Arrays ans classes “#include#includeclass queue{private:int front,rear,max;int *queuearr;public:queue(){cout<<"\nEnter the size of Queue: ";cin>>max;front=0,rear=-1;int *Queue=new int[max];}void push(int n){if(rear==max)cout<<"\nQueue is full\n";elserear=rear+1;queuearr[rear]=n;}void pop(){if(front==-1 && rear==-1)cout<<"\nQueue is empty\n";elsecout<<"\nThe Queue element "<<queuearr[front]<<" is poped\n";for(front=0;front<rear;front++)    {queuearr[front]=queuearr[front+1]; }rear=rear-1;}void display(){ for(int i=0;i<=rear;i++)cout<<"\nvalue is :"<<queuearr[i];}};void main(){clrscr();int a=0,value=0;queue obj;while(getch()!=27){cout<<"\n \n\n\t\tSelect an option:\n 1   for Insert\n 2Continue reading “Implementation of linear Queue in C++”

Implementation Of Circular Queue in C++

Implementation Of Circular Queue in C++ Using Array #include#include#define max 5class queue{private:int front,rear;int *queue;public:queue(){   cout<<"\nThe size of Queue is Already = 5 or put 5 ";     cin>>max;   front=rear=-1;}void insert_rear(int n){ if((front==0 && rear==max)||(front==(rear+1))) { cout<<"\nQueue is Full\n"; } else if(front==-1 && rear==-1)    {  front=rear=0;      queue[rear]=n;    }    else if ( rear==max &&Continue reading “Implementation Of Circular Queue in C++”

Data Structure Programs

“All Data Structure Programs up-till now” To get code Click on that program heading 🙂 ☺ ☻   ALL Type Of Sorting : Click here :: most important ::  ——————- TREES:-   RED AND BLACK TREE IN C++Insertion- Deletion- Searching -Max,Min Tree C++ Code Tree Non Liner Data Structure    Insert 100 in all Leaf nodes and 10 in all nonContinue reading “Data Structure Programs”