Skip to content

Commit

Permalink
Corrected Indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
anmoljagetia committed May 8, 2014
1 parent aaa57b1 commit 53b68d5
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 8 deletions.
59 changes: 59 additions & 0 deletions Graph/BFS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
queue<int> q;
int i, n, e, x, y, cv, f;
cv = 1;
cout << "Enter no of nodes" << endl;
cin >> n;

cout << "Enter no of edges" << endl;
cin >> e;

int visit[n + 1];

for (i = 1; i <= n; ++i) {
visit[i] = 0;
}

vector<int> v[n + 1];
//created an array of vectors to store the adjacency list n is equal to no of nodes
//each row of this adjacency list shows the conencted edges of that particular vertex

//creating the adjacency list
for (i = 0; i < e; i++) {
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}

q.push(cv);
visit[cv] = 1;

cout << "BFS of the given graph \n";
while(!q.empty()) {
f = q.front();
q.pop();
cout << f << " ";

//until all connected vertices are in the queue
for(i = 0; i < v[f].size(); i++) {
//if not previously visited
if (visit[v[f][i]] == 0) {
//push in queue and and the vertex to visited list
q.push(v[f][i]);
visit[v[f][i]] = 1;
}
}
}

return 0;
}
42 changes: 42 additions & 0 deletions Graph/DFS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
stack<int> s;
int i, n, e, x, y, cv, f;
cv = 1;
cout << "Enter no of nodes" << endl;
cin >> n;

cout << "Enter no of edges" << endl;
cin >> e;

vector<int> visit;

vector<int> v[n + 1];
//created an array of vectors to store the adjacency list n is equal to no of nodes
//each row of this adjacency list shows the conencted edges of that particular vertex

//creating the adjacency list
for (i = 0; i < e; i++) {
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}

s.push(cv);
cout << "BFS of the given graph \n";
while(s.size() != n) {
f = (int)s.pop();
x = v[f][0];
}

return 0;
}
8 changes: 8 additions & 0 deletions Graph/in.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
8 7
3 5
1 4
1 3
2 5
3 6
4 7
4 8
4 changes: 2 additions & 2 deletions Searching/BSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int Bsearch (int a[], int k, int p, int r)
int m;
m = (p + r)/2;
if (a[m] == k) {
cout<<"ELement Found at "<<m<<"th index"<<endl;
cout << "ELement Found at " << m << "th index" << endl;
return 1;
}
else if (k < a[m]) {
Expand All @@ -24,7 +24,7 @@ int Bsearch (int a[], int k, int p, int r)
void status (int s)
{
if (s == 0) {
cout<<"Element not found"<<endl;
cout << "Element not found" << endl;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Searching/LSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ int main(int argc, char const *argv[])
}

if(j == -1) {
cout<<"Element not found"<<endl;
cout << "Element not found" << endl;
}
else {
cout<<"Element found at "<<j<<"th index of array"<<endl;
cout << "Element found at " << j << "th index of array" << endl;
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion Sorting/Heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int main()

// printing sorted array
for (i = 0; i < SIZE; i++) {
cout<<a[i]<<"\t";
cout << a[i] << "\t";
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion Sorting/Insertion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main(int argc, char const *argv[])

//printing sorted array
for (i = 0; i < SIZE; i++) {
cout<<a[i]<<"\t";
cout << a[i] << "\t";
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion Sorting/Merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int main()

// printing sorted array
for (i = 0; i < SIZE; i++) {
cout<<a[i]<<"\t";
cout << a[i] << "\t";
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion Sorting/Selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int main(int argc, char const *argv[])

//printing sorted array
for (i = 0; i < SIZE; i++) {
cout<<a[i]<<"\t";
cout << a[i] << "\t";
}

return 0;
Expand Down

0 comments on commit 53b68d5

Please sign in to comment.