Skip to content

Commit 47c8d55

Browse files
committed
sorting algorithms in cpp
0 parents  commit 47c8d55

37 files changed

+400
-0
lines changed

BFS/code.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
struct node
4+
{
5+
int u, v;
6+
};
7+
int main()
8+
{
9+
queue <int> q;
10+
q.push(10);
11+
q.push(20);
12+
q.push(30);
13+
14+
cout << q.front() << " " << q.size() << endl;
15+
q.pop();
16+
17+
cout << q.front() << " " << q.size() << endl;
18+
19+
queue <node> sq;
20+
sq.push({1,2});
21+
sq.push({3,4});
22+
sq.push({6,7});
23+
24+
node t = sq.front();
25+
26+
cout << t.u << ' ' << t.v << ' ' << sq.size() << endl;
27+
28+
sq.pop();
29+
t = sq.front();
30+
cout << t.u << ' ' << t.v << ' ' << sq.size() << endl;
31+
32+
33+
}

BFS/code.exe

123 KB
Binary file not shown.

BFS/code.o

117 KB
Binary file not shown.

BFS/graph.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
int graph[10][10];
4+
5+
int main()
6+
{
7+
int V, E, S, D;
8+
cout << "Enter the number of vartexes: ";
9+
cin >> V;
10+
11+
cout << "Enter the number of edges: ";
12+
cin >> E;
13+
14+
cout << "Input Every Edge: ";
15+
16+
for(int i = 1; i <= E; i++){
17+
int u, v;
18+
cin >> u >> v;
19+
graph[u][v] = graph[v][u] = 1;
20+
}
21+
22+
cout << "Enter Source: ";
23+
cin >> S;
24+
25+
cout << "Enter Destination: ";
26+
cin >> D;
27+
28+
for(int i = 1; i <= V; i++){
29+
for(int j = 1; j <= V; j++){
30+
cout << graph[i][j] << '\t';
31+
}
32+
cout << '\n';
33+
}
34+
return 0;
35+
}

BFS/graph.exe

59.1 KB
Binary file not shown.

BFS/graph.o

5.56 KB
Binary file not shown.

BFS/queue.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
struct node
4+
{
5+
int u, v;
6+
};
7+
int main()
8+
{
9+
queue <int> q;
10+
q.push(-50);
11+
q.push(10);
12+
q.push(20);
13+
14+
cout << q.front() << " " << q.size() << endl;
15+
q.pop();
16+
17+
cout << q.front() << " " << q.size() << endl;
18+
19+
queue <node> sq;
20+
sq.push({1,2});
21+
sq.push({3,4});
22+
23+
node t = sq.front();
24+
cout << t.u << ' ' << t.v << endl;
25+
26+
sq.pop();
27+
t = sq.front();
28+
cout << t.u << ' ' << t.v << endl;
29+
30+
return 0;
31+
}

BFS/queue.exe

122 KB
Binary file not shown.

BFS/queue.o

114 KB
Binary file not shown.

Bubble Sort/code.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
void bubble(int n, int arr[]){
4+
for(int i = 1; i <= n -1; i++){
5+
for(int j = 1; j <= n - i; j++){
6+
if(arr[j] > arr[j+1]) swap(arr[j],arr[j+1]);
7+
}
8+
}
9+
}
10+
int main()
11+
{
12+
int arr[100], n;
13+
cout<<"Enter the array size: ";
14+
cin>>n;
15+
16+
cout<<"Enter the array: ";
17+
for(int i = 1; i <= n; i++) cin>>arr[i];
18+
bubble(n,arr);
19+
for(int i = 1; i <= n; i++) cout<<arr[i];
20+
return 0;
21+
}

0 commit comments

Comments
 (0)