-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
11,476 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <bits/stdc++.h> | ||
|
||
int arr[10]; | ||
|
||
int part(int low, int high) { | ||
int pivot = arr[high]; | ||
int temp, i = low - 1; | ||
|
||
for(int j = low; j <= high - 1; j ++) { | ||
if(arr[j] <= pivot) { | ||
i++; | ||
temp = arr[i]; | ||
arr[i] = arr[j]; | ||
arr[j] = temp; | ||
} | ||
} | ||
temp = arr[i+1]; | ||
arr[i+1] = arr[high]; | ||
arr[high] = temp; | ||
|
||
return (i + 1); | ||
} | ||
|
||
void quick_sort(int low, int high) { | ||
if(low < high) { | ||
int partition = part(low, high); | ||
quick_sort(low, partition-1); | ||
quick_sort(partition+1, high); | ||
} | ||
} | ||
|
||
void print_arr(int n) { | ||
for(int i = 0; i < n; i ++) { | ||
printf("%d ",arr[i]); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
int main() { | ||
int n; | ||
scanf("%d",&n); | ||
|
||
for(int i = 0; i < n; i ++) | ||
scanf("%d",&arr[i]); | ||
|
||
quick_sort(0, n - 1); | ||
|
||
print_arr(n); | ||
|
||
return 0; | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
vector<int> adj[10]; | ||
bool visited[10]; | ||
int num; | ||
|
||
void dfs(int source) { | ||
visited[source] = true; | ||
num += 1; | ||
for(int i = 0; i < adj[source].size(); ++i) | ||
if(visited[adj[source][i]] == false) { | ||
dfs(adj[source][i]); | ||
} | ||
} | ||
|
||
void initialize(int n) { | ||
for(int i = 0; i < n; i ++) | ||
visited[i] = false; | ||
} | ||
|
||
int main() { | ||
//Number of nodes and edges resp. | ||
int n, m; | ||
scanf("%d %d", &n, &m); | ||
|
||
int x, y; | ||
for(int i = 0 ; i < m; i ++) { | ||
scanf("%d %d",&x,&y); | ||
adj[x].push_back(y); | ||
adj[y].push_back(x); | ||
} | ||
|
||
initialize(m); | ||
|
||
int source; | ||
scanf("%d",&source); | ||
|
||
num = 0; | ||
if(visited[source] == false) | ||
dfs(source); | ||
|
||
printf("%d\n",n - num); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
vector<int> vert[10]; | ||
bool visited[10]; | ||
|
||
void dfs(int s) { | ||
visited[s] = true; | ||
printf("%d->",s); | ||
for(int i = 0; i < vert[s].size(); ++i) { | ||
if(visited[vert[s][i]] == false) { | ||
dfs(vert[s][i]); | ||
} | ||
} | ||
} | ||
|
||
void initialize(int v) { | ||
for(int i = 0; i < v; i ++) { | ||
visited[i] = false; | ||
} | ||
} | ||
|
||
int main() { | ||
int v, e; | ||
scanf("%d",&v); | ||
scanf("%d",&e); | ||
|
||
int x, y; | ||
for(int i = 0; i < e; i ++) { | ||
scanf("%d %d",&x,&y); | ||
vert[x].push_back(y); | ||
vert[y].push_back(x); | ||
} | ||
|
||
initialize(v); | ||
|
||
printf("Begin->"); | ||
|
||
for(int i = 0; i < v; i ++) { | ||
if(visited[i] == false) { | ||
dfs(i); | ||
printf("\n"); | ||
//connectedComponents++; | ||
} | ||
} | ||
|
||
printf("End"); | ||
//printf("Number of connected components\n->%d"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
10 10 | ||
8 1 | ||
8 3 | ||
7 4 | ||
7 5 | ||
2 6 | ||
10 7 | ||
2 8 | ||
10 9 | ||
2 10 | ||
5 10 | ||
2 |
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
10 | ||
9061 | ||
7432 | ||
3768 | ||
2305 | ||
5318 | ||
4837 | ||
3457 | ||
4761 | ||
7827 | ||
1528 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
100 | ||
9061 | ||
7432 | ||
3768 | ||
2305 | ||
5318 | ||
4837 | ||
3457 | ||
4761 | ||
7827 | ||
1528 | ||
9830 | ||
1030 | ||
1079 | ||
82 | ||
5303 | ||
9049 | ||
7848 | ||
8694 | ||
1375 | ||
4678 | ||
4895 | ||
8471 | ||
6321 | ||
3552 | ||
3695 | ||
5738 | ||
3278 | ||
8947 | ||
1492 | ||
7609 | ||
6275 | ||
4770 | ||
5019 | ||
4260 | ||
1292 | ||
4554 | ||
9097 | ||
4750 | ||
3532 | ||
6901 | ||
495 | ||
3339 | ||
2148 | ||
1574 | ||
7661 | ||
1669 | ||
4841 | ||
5486 | ||
4580 | ||
6216 | ||
4382 | ||
9475 | ||
8905 | ||
680 | ||
3005 | ||
2577 | ||
635 | ||
500 | ||
1501 | ||
6367 | ||
8109 | ||
7776 | ||
1115 | ||
3105 | ||
6254 | ||
6647 | ||
1876 | ||
5328 | ||
5614 | ||
5408 | ||
6447 | ||
327 | ||
2964 | ||
8595 | ||
1901 | ||
603 | ||
4481 | ||
959 | ||
306 | ||
9062 | ||
1393 | ||
8928 | ||
8514 | ||
275 | ||
9608 | ||
5736 | ||
7092 | ||
221 | ||
6236 | ||
8593 | ||
6588 | ||
4323 | ||
563 | ||
1920 | ||
1645 | ||
6817 | ||
2785 | ||
3522 | ||
6363 | ||
8399 |
Oops, something went wrong.