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] +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; +}