diff --git a/c++/Bubble_Sort.cpp b/c++/Bubble_Sort.cpp new file mode 100644 index 0000000..b1d6769 --- /dev/null +++ b/c++/Bubble_Sort.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; + +int main() { + + int i,j,a[1000],n; + cin>>n; + + for (i=0;i<=n-1;i++){ + cin>>a[i]; + } + for (i=0;ia[j+1]){ + swap(a[j],a[j+1]); + } + } + } + + for (i=0;i<=n-1;i++){ + cout< +using namespace std; + +bool compare1(int a, int b){ + + return a < b; +} + +bool compare2(int a, int b){ + + return a > b; +} +int main(){ + int i,j,n; + cin>>n; + + int a[n]; + + for(i=0;i<=n-1;i++){ + cin>>a[i]; + } + + sort( a , a+n ); + + for(i=0;i<=n-1;i++){ + cout< +using namespace std; + +int main() { + int i, j,n,temp; + cin>>n; + int a[n]; + + for(i=0;i<=n-1;i++){ + cin>>a[i]; + } + + for(i=1;i<=n-1;i++){ + temp = a[i]; + j = i-1; + while(j>=0 && a[j]>temp){ + + a[j+1] = a[j]; + j-- ; + } + + a[j+1] = temp; + } + + for(i=0;i<=n-1;i++){ + cout< +using namespace std; + +int main(){ + + int n,key; + cin>>n; + + int a[n],i; + + for( i=0;i>a[i]; + } + + cout<<"Enter the digit u want to find "<>key; + + for( i =0;i +using namespace std; + +int Solution(int arr[], int n) +{ + + // If length of array is even + if (n % 2 == 0) + { + int z = n / 2; + int e = arr[z]; + int q = arr[z - 1]; + int ans = (e + q) / 2; + return ans; + } + + // If length if array is odd + else + { + int z = round(n / 2); + return arr[z]; + } +} + +// Driver Code +int main() { + + // TODO Auto-generated method stub + int arr1[] = {2, 3, 5, 8}; + int arr2[] = {10, 12, 14, 16, 18, 20}; + + int i = sizeof(arr1) / sizeof(arr1[0]); + int j = sizeof(arr2) / sizeof(arr2[0]); + + int arr3[i+j]; + int l = i+j; + // Merge two array into one array + for(int k=0;k +using namespace std; +int main(){ + int i,curr_sum = 0 , max_sum =0,n; + cin>>n; + + int a[n]; + + for(i=0;i>a[i]; + } + + for(i=0;i +using namespace std; +int main(){ + int i=0 ,j, a[] = {1,3,5,7,9,11,13,14 } , sum=14; //this method only works for sorted arrays to give pairs having a particular sum + j = sizeof(a)/sizeof(int) - 1; //it gives us n-1 + + while(i sum ){ + j--; //since in sorted array if i moves it will only increase its value so j-- + } + + else if (curr_Sum < sum){ + i++; + } + + else if(curr_Sum == sum){ + + cout< +using namespace std; + +int binarySearch(int a[],int n,int key){ + int s=0,mid,e= n-1; + + while(s<=e){ + + mid=(s+e)/2; + + if(a[mid]==key){ + return mid; //will return the value of the index and loop and funt'n will stop here + } + else if (a[mid]>key){ + e = mid - 1; + } + else if(a[mid]>n; + + int a[n]; + + for(int i=0;i>a[i]; + } + + cout<<"Enter the digit u want to find "<>key; + + cout<