From 087aa3a80d8070fbd890e0d9486f603282a6d93c Mon Sep 17 00:00:00 2001 From: MEGHWANT SINGH <68533246+Meghwantsingh@users.noreply.github.com> Date: Tue, 5 Oct 2021 11:09:17 +0530 Subject: [PATCH 1/2] Create binary-search.cpp Binary search program ..in C++ language . Check if get any issue replay . Sorry if I did something wrong bez I am new to this. Github: https://github.com/Meghwantsingh/Hacktoborfest-2021 --- binary-search.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 binary-search.cpp diff --git a/binary-search.cpp b/binary-search.cpp new file mode 100644 index 0000000..4b3020e --- /dev/null +++ b/binary-search.cpp @@ -0,0 +1,48 @@ + +//Binary search .................Iterative method best for sorted array + +# include +using namespace std; //std::cout or std::cin + +int main(){ + int n,t; + cout<<"enter test cases"<>t; + //cout<<(sizeof(arr)/sizeof(arr[0])); sizeof(arr) = datatype of arr * number of variable + while(t--){ + cout<<"enter size of array "<>n; + int arr[n]; + cout<<"Enter array element\n"; + + for(int i=0;i>arr[i]; + } + + int key; + cout<<"enter key to search"<>key; + + int low=0,high=n-1, flag=0; + for(int i=0;ikey){ + high= mid-1; + } + else if(arr[mid] Date: Tue, 5 Oct 2021 11:37:37 +0530 Subject: [PATCH 2/2] Create floyd_Warshall.cpp Floyd Warshall algorithm is added . Github : https://github.com/Meghwantsingh If any error pls replay. --- floyd_Warshall.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 floyd_Warshall.cpp diff --git a/floyd_Warshall.cpp b/floyd_Warshall.cpp new file mode 100644 index 0000000..bb1ed41 --- /dev/null +++ b/floyd_Warshall.cpp @@ -0,0 +1,60 @@ +// Floyd Warshall algorithm + // Use to find all pairs of shortest path +#include +using namespace std; + +#define V 4 // Number of vertices in graph problem + +#define INF INT_MAX // INF infinite maximum distance value for not connected vertices header file used + +void output(int dist[][V]) // output matrix show here +{ + + cout<<"ALL SHORTEST PATH FOR EVERY VERTICES\n"; + + + for(int i=0;idist[i][k]+dist[k][j]) && (dist[i][k]!=INF) &&(dist[k][j]!=INF)) + dist[i][j]=dist[i][k]+dist[k][j]; + + } + } + } + output(dist); // print shortest matrix +} + +int main(){ + +int g[V][V]={{0,3,INF,7},{8,0,2,INF},{5,INF,0,1},{2,INF,INF,0}}; // index value 0 show self loop edges and INF infinite largest distance + + +flyodWarshall(g); // use to find paths + +return 0; +}