Skip to content

Commit

Permalink
updated for hacktoberfest 2021
Browse files Browse the repository at this point in the history
  • Loading branch information
TAbhay committed Sep 12, 2021
1 parent f4ce16d commit 32baa17
Show file tree
Hide file tree
Showing 80 changed files with 1,714 additions and 1,547 deletions.
166 changes: 83 additions & 83 deletions Graphs/BFS.txt → Hacktoberfest_2020/Graphs/BFS.txt
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
#include <iostream>
using namespace std;
class queue{
int front;
int rear;
int size;
int *q;
public:
queue(){front=rear=-1;q=new int[10];}
queue(int size){front =rear=-1;this->size=size;q=new int[this->size];}
void enqueue(int x);
int dequeue();
int Isempty();
};
void queue:: enqueue(int x){
if(rear==size-1){
cout<<"full";
}
else {
rear++;
q[rear]=x;
}
}
int queue:: Isempty(){
if(front==rear){
return 0;
}
else 1;
}
int queue::dequeue(){int x;
if(front==rear){
cout<<"Empty";
}
else{
front++;
x=q[front];
}
return x;
}
void Breadth_first_Search(int u,int A[8][8],int n){
queue qt(8); int k;
int visited[8]={0};
cout<<u<<endl;
visited[u]=1;
qt.enqueue(u);
while(!qt.Isempty()){
k=qt.dequeue();
for(int i=1;i<=n;i++){
if(A[k][i]==1 && visited[i]==0){
cout<<i<<endl;
qt.enqueue(i);
visited[i]=1;
}
}
}
}
int main()
{
int B[8][8] = {{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 0, 0, 0},
{0, 1, 0, 1, 0, 0, 0, 0},
{0, 1, 1, 0, 1, 1, 0, 0},
{0, 1, 0, 1, 0, 1, 0, 0},
{0, 0, 0, 1, 1, 0, 1, 1},
{0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0}};
cout << "Vertex: 1 -> " << flush;
Breadth_first_Search(1,B,8);
cout<<endl;
cout << "Vertex: 5 -> " << flush;
Breadth_first_Search(5,B,8);
return 0;
}
#include <iostream>

using namespace std;

class queue{
int front;
int rear;
int size;
int *q;
public:
queue(){front=rear=-1;q=new int[10];}
queue(int size){front =rear=-1;this->size=size;q=new int[this->size];}
void enqueue(int x);
int dequeue();
int Isempty();

};
void queue:: enqueue(int x){
if(rear==size-1){
cout<<"full";
}
else {
rear++;
q[rear]=x;

}
}
int queue:: Isempty(){
if(front==rear){
return 0;
}
else 1;
}

int queue::dequeue(){int x;
if(front==rear){
cout<<"Empty";
}
else{
front++;
x=q[front];

}
return x;

}
void Breadth_first_Search(int u,int A[8][8],int n){
queue qt(8); int k;
int visited[8]={0};
cout<<u<<endl;
visited[u]=1;
qt.enqueue(u);
while(!qt.Isempty()){
k=qt.dequeue();
for(int i=1;i<=n;i++){
if(A[k][i]==1 && visited[i]==0){
cout<<i<<endl;
qt.enqueue(i);
visited[i]=1;
}
}
}


}
int main()
{
int B[8][8] = {{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 0, 0, 0},
{0, 1, 0, 1, 0, 0, 0, 0},
{0, 1, 1, 0, 1, 1, 0, 0},
{0, 1, 0, 1, 0, 1, 0, 0},
{0, 0, 0, 1, 1, 0, 1, 1},
{0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0}};
cout << "Vertex: 1 -> " << flush;
Breadth_first_Search(1,B,8);
cout<<endl;
cout << "Vertex: 5 -> " << flush;
Breadth_first_Search(5,B,8);

return 0;
}
66 changes: 33 additions & 33 deletions Graphs/DFS.txt → Hacktoberfest_2020/Graphs/DFS.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#include <iostream>
using namespace std;
Depth_first_Search(int u,int B[8][8],int n)
{
int i ;
static int visited[8]={0};
if(visited[u]==0)
{ cout<<u<<" ";
visited[u]=1;
for(i=1;i<n;i++)
{
if(B[u][i]==1 && visited[i]==0)
Depth_first_Search(i,B,n);
}
}
}
int main()
{
int B[8][8] = {{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 0, 0, 0},
{0, 1, 0, 1, 0, 0, 0, 0},
{0, 1, 1, 0, 1, 1, 0, 0},
{0, 1, 0, 1, 0, 1, 0, 0},
{0, 0, 0, 1, 1, 0, 1, 1},
{0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0}};
cout << "DFS Vertex: " << 4 << " -> " ;
Depth_first_Search(4,B,8);
return 0;
}
#include <iostream>
using namespace std;


Depth_first_Search(int u,int B[8][8],int n)
{
int i ;
static int visited[8]={0};
if(visited[u]==0)
{ cout<<u<<" ";
visited[u]=1;
for(i=1;i<n;i++)
{
if(B[u][i]==1 && visited[i]==0)
Depth_first_Search(i,B,n);
}
}
}
int main()
{
int B[8][8] = {{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 0, 0, 0},
{0, 1, 0, 1, 0, 0, 0, 0},
{0, 1, 1, 0, 1, 1, 0, 0},
{0, 1, 0, 1, 0, 1, 0, 0},
{0, 0, 0, 1, 1, 0, 1, 1},
{0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0}};
cout << "DFS Vertex: " << 4 << " -> " ;
Depth_first_Search(4,B,8);

return 0;
}
Loading

0 comments on commit 32baa17

Please sign in to comment.