diff --git a/01_introduction_to_algorithms/c++/01_binary_search.cpp b/01_introduction_to_algorithms/c++/01_binary_search.cpp new file mode 100644 index 0000000..a82958e --- /dev/null +++ b/01_introduction_to_algorithms/c++/01_binary_search.cpp @@ -0,0 +1,40 @@ +#include "iostream" +using namespace std; + +void binarySearch(int data_array[], int element, int len) +{ + int low = 0; + int high = len; + while (low <= high) + { + int mid = (low + high)/2; + int guess = data_array[mid]; + + if (guess == element) + { + cout<<"Element found at "< element) + { + high = mid - 1; + } + else + { + low = mid + 1; + } + } + cout<<"Element Not Found"< +#include +#include +#include +using namespace std; +template +class Graph { + map > adjList ; + + public : + Graph() + {} + + void addEdge(T u , T v , bool bidir = true) + { + adjList[u].push_back(v); + if(bidir) + adjList[v].push_back(u) ; + } + + void printAdjList() + { + for( auto key : adjList) + { + cout<" ; + for(auto neighbours : key.second) + cout< q; + + map visited ; + + q.push(src) ; + visited[src] = true ; + + while(!q.empty()) + { + T node = q.front() ; + cout< g ; + + //adding the edges in the Graph + g.addEdge(0,1); + g.addEdge(1,2); + g.addEdge(0,4); + g.addEdge(2,4); + g.addEdge(2,3); + g.addEdge(3,5); + g.addEdge(3,4); + + cout <<"The Graph is"<