From d509fe1067bc6937dbf31a2b56bf6f5d3ec9d7de Mon Sep 17 00:00:00 2001 From: AdithyakrishnaV Date: Thu, 23 Sep 2021 13:42:09 +0530 Subject: [PATCH] C++ notes --- Binery_search.cpp | 51 ++++++++++++++++++++++++++++++ Kandane's_algorithum.cpp | 35 +++++++++++++++++++++ cyclicshift.cpp | 19 ++++++++++++ function1.cpp | 67 ++++++++++++++++++++++++++++++++++++++++ pointers.cpp | 38 +++++++++++++++++++++++ sets.cpp | 25 +++++++++++++++ unordered_map.cpp | 39 +++++++++++++++++++++++ 7 files changed, 274 insertions(+) create mode 100644 Binery_search.cpp create mode 100644 Kandane's_algorithum.cpp create mode 100644 cyclicshift.cpp create mode 100644 function1.cpp create mode 100644 pointers.cpp create mode 100644 sets.cpp create mode 100644 unordered_map.cpp diff --git a/Binery_search.cpp b/Binery_search.cpp new file mode 100644 index 0000000..3536506 --- /dev/null +++ b/Binery_search.cpp @@ -0,0 +1,51 @@ + + + //Binery Search + +#include +using namespace std; + +int findIndex(int a[], int n, int target) +{ + int low=0, mid, high=n-1; + + while(low<=high){ + mid=(low+high)/2; + + if(a[mid]==target){ + return mid; + } + else if(a[low]<=a[mid]){ + if(target<=a[mid] && target >= a[low]){ + high=mid-1; + }else{ + low=mid+1; + } + } + else{ + if(target>=a[mid] && target<=a[high]){ + low=mid+1; + }else{ + high=mid-1; + } + } + } + return -1; +} + +int main(){ + int n; + cin>>n; + + int a[n]; + for (int i = 0; i < n; i++){ + cin>>a[i]; + } + + int target; + cin>>target; + + cout< +// using namespace std; + +// int main(){ +// int n; +// cin>>n; + +// int a[n]; + +// for(int i=0; i>a[i]; +// } + +// int max_sum = INT_MIN, current_sum=0; + +// for(int i=0; i max_sum){ +// max_sum = current_sum; +// } +// if(current_sum < 0){ +// current_sum = 0; +// } + +// } + +// cout< +using namespace std; + +int main(){ + int arr[]={1,2,3,4,5,6,7,8,9}; + int n=9; + int k=4; + + reverse(arr, arr+n-k); + reverse(arr+n-k, arr+n); + reverse(arr, arr+n); + + for(int i=0; i +using namespace std; + +//function declaration +void party (string); + +//function definition +void party(string n){ + cout<<"hey "< +// using namespace std; + +// //function declaration +// void multiply5(int&); + +// //function definition +// void multiply5(int& a){ +// a=a*5; +// } + +// int main(){ +// int x=10; +// //function calling +// multiply5(x); +// cout< +// using namespace std; + +// //function definition +// string stringConvert(string s){ +// string res=s; +// for(int i=0; i=0 && s[i]-'A'<= 25){ //big to small +// res[i]=res[i]-'A'+'a'; +// }else if(s[i]-'a'>=0 && s[i]-'a'<= 25){ //small to big +// res[i]=res[i]-'a'+'A'; +// } +// } +// return res; +// } + +// int main(){ +// string s="adithya&*&DSNFKJHDKSFKDSFKD"; +// string res1=stringConvert(s); +// cout< +using namespace std; + +int main(){ + int a=25; + int *p=&a; + cout< +using namespace std; + +int main(){ + char a=63; + void* p=&a; + + cout< +using namespace std; + +int main(){ + char a=63; + void* p=&a; + + cout<<*(char*)p<<"\n"; + + return 0; +} \ No newline at end of file diff --git a/sets.cpp b/sets.cpp new file mode 100644 index 0000000..a16126a --- /dev/null +++ b/sets.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; + +int main(){ + set s; + + s.insert(4); + s.insert(3); + s.insert(1); + s.insert(2); + + for(int element:s){ + cout< +using namespace std; + +int main(){ + int n; //length of the array + cin>>n; + + int a[n]; //an array of length n + + for(int i=0; i>a[i]; + } + + unordered_map mp; + + int sum = 0, find_sub=0; + + for(int i=0;i0){ + find_sub = 1; + }else{ + mp[sum]++; + } + } + } + if(find_sub == 1){ + cout<<"True"<