forked from AdarshAddee/Hacktoberfest2022_for_Beginers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
616 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
chiragchandnani10 | ||
https://github.com/chiragchandnani10 | ||
*/ | ||
|
||
#include<bits/stdc++.h> | ||
using namespace std; | ||
void merging(int input[],int start,int end){ | ||
int mid = (start+end)/2; | ||
int i=start, j=mid+1, k=start; | ||
int ans[end+1]; | ||
while(i<=mid&&j<=end){ | ||
if(input[i]<input[j]){ | ||
ans[k]=input[i]; | ||
i++; | ||
k++; | ||
} | ||
else{ | ||
ans[k]=input[j]; | ||
j++; | ||
k++; | ||
} | ||
} | ||
while(i<=mid){ | ||
ans[k]=input[i]; | ||
i++; | ||
k++; | ||
} | ||
while(j<=end){ | ||
ans[k]=input[j]; | ||
j++; | ||
k++; | ||
} | ||
for(int s=start;s<=end;s++){ | ||
input[s]=ans[s]; | ||
} | ||
} | ||
|
||
void merge_sort(int input[],int start,int end){ | ||
if(start>=end){ | ||
return; | ||
} | ||
int mid = ((start+end)/2); | ||
merge_sort(input,start,mid); | ||
merge_sort(input,mid+1,end); | ||
merging(input,start,end); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
void mergeSort(int input[], int size){ | ||
// Write your code here | ||
|
||
merge_sort(input,0,size-1); | ||
|
||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Author: ADARSH | ||
// Date Modified: 01/10/2022 | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
bool isPowerOf2(int n) { | ||
return (n && !(n & (n - 1))); | ||
} | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
int n; | ||
cout << "Enter a number: "; | ||
cin >> n; | ||
cout << ((isPowerOf2(n)) ? "It's a power of 2." : "It's not a power of 2."); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include<iostream> | ||
using namespace std; | ||
// github username navdeepk037 https://github.com/navdeepk037 | ||
int fact(int n) | ||
{ | ||
int factorial=1; | ||
for(int i=n;i>=1;i--) | ||
factorial=factorial*i; | ||
return factorial; | ||
} | ||
int main(){ | ||
int n; | ||
cout<<"enter the number "; | ||
cin>>n; | ||
cout<<"the factorial of the number is "<<fact(n); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Author : Prathamesh Patil | ||
In selection sort, | ||
we get the least from array and place it at first position, then recursively leaving the first element do the same | ||
*/ | ||
|
||
|
||
#include<stdio.h> | ||
|
||
//declaration of display function | ||
void display(int array[], int size) | ||
{ | ||
for (int i = 0; i < size; i++) | ||
{ | ||
printf("%d ", array[i]); | ||
} | ||
} | ||
|
||
//declaration of funtion :- selection sort | ||
void selection_sort(int array[], int size) | ||
{ | ||
int least, i, j, temp, l; | ||
|
||
for ( i = 0; i < size; i++) //loop for accessing the ith element from array | ||
{ | ||
least = array[i]; //taking the i element as the least starting from 0 | ||
printf("Least : %d") | ||
|
||
for ( j = i + 1; j < size; j++) //loop for comparing the array elements with ith element | ||
{ | ||
if (least > array[j]) //getting the least element from the array | ||
{ | ||
least = array[j]; //storing it in the least variable | ||
l=j; //storing the index of least variable in l | ||
} | ||
} | ||
//swap logic in least and ith element | ||
temp = array[i]; | ||
array[i] = array[l]; | ||
array[l] = temp; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int array[5] = {23,11,1,35,21}; | ||
int size = 5; | ||
|
||
//calling the selection_sort funtion | ||
selection_sort(array, size); | ||
|
||
//calling the display function | ||
display(array, size); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
| Khushi Marothi | <a href="https://github.com/khushimarothi">Khushi Marothi</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Aditya Giri | <a href="https://github.com/aditya-464">Aditya Giri</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| KryPtoN | <a href="https://github.com/Kry9toN">Kry9toN</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Udyansingh | <a href="https://github.com/Udyansingh">Udyan Singh</a> | <a href="[email protected]">E-Mail</a> | | ||
| Hardik Pratap Singh | <a href="https://github.com/hardik-pratap-singh">Hardik Pratap Singh</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Suraj Bhandarkar S | <a href="https://github.com/Suraj-Bhandarkar-S">Adarsh Addee</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Ashutosh Shukla|<a href = "https://github.com/AshutoshBuilds">Ashutosh Shukla</a>|<a href ="[email protected]">E-mail</a> | | ||
|
@@ -30,6 +31,19 @@ | |
| Anurag Vats | <a href="https://github.com/AnuragVats007">Anurag Vats</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Daksh Kesarwani | <a href="https://github.com/InnocentDaksh63">Daksh kesaarwani</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Pradeep Khatri | <a href="https://github.com/PradeepKhatri">Pradeep Khatri</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Apurva Dubey | <a href="https://github.com/umbridge">umbridge</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Daksh Kesarwani | <a href="https://github.com/InnocentDaksh63">Daksh kesaarwani</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Chirag Chandnani | <a href="https://github.com/chiragchandnani10">Chirag Chandnani</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Shivam Jaiswal | <a href="https://github.com/Shivaminc">Shivam Jaiswal</a> | <a href="mailto:[email protected]">E-mail</a> | | ||
| Ashish Kushwaha | <a href="https://github.com/AshishKingdom">Ashish Kushwaha</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Dhruv Arora | <a href="https://github.com/lord-benjamin">Dhruv Arora</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Tharindu Sooriyaarchchi | <a href="https://github.com/TharinduDilshan>Tharindu Sooriyaarchchi</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Samriddh Prasad | <a href="https://github.com/Samriddh2703">Samriddh Prasad</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Edgar Gonzalez | <a href="https://github.com/Edgarzerocool">Edgar Gonzalez</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//Print 1 to 100 without using numbers | ||
void main() { | ||
int limite = int.parse("100"); | ||
for (int i = 1; i <= limite; i++) { | ||
print(i); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/*Tharindu Sooriyaarachchi - https://github.com/TharinduDilshan */ | ||
public class InsertionSort | ||
{ | ||
void insert(int a[]) | ||
{ | ||
int i, j, temp; | ||
int n = a.length; | ||
for (i = 1; i < n; i++) { | ||
temp = a[i]; | ||
j = i - 1; | ||
|
||
while(j>=0 && temp <= a[j]) | ||
{ | ||
a[j+1] = a[j]; | ||
j = j-1; | ||
} | ||
a[j+1] = temp; | ||
} | ||
} | ||
void printArr(int a[]) | ||
{ | ||
int i; | ||
int n = a.length; | ||
for (i = 0; i < n; i++) | ||
System.out.print(a[i] + " "); | ||
} | ||
|
||
public static void main(String[] args) { | ||
int a[] = { 92, 50, 5, 20, 11, 22 }; | ||
InsertionSort i1 = new InsertionSort(); | ||
System.out.println("\nBefore sorting array elements are - "); | ||
i1.printArr(a); | ||
i1.insert(a); | ||
System.out.println("\n\nAfter sorting array elements are - "); | ||
i1.printArr(a); | ||
System.out.println(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//Github Username: Udyansingh | ||
|
||
import java.util.Arrays; | ||
import java.util.Scanner; | ||
|
||
public class QuickSort { | ||
|
||
public static int partition(int[] arr, int si, int ei) { | ||
int pid, piv = arr[si], count = 0, i = si; | ||
for (i = si + 1; i <= ei; i++) { | ||
if (arr[i] <= piv) { | ||
count++; | ||
} | ||
} | ||
pid = count + si; | ||
arr[si] = (arr[pid] + arr[si]) - (arr[pid] = arr[si]); | ||
while (si < pid && ei > pid) { | ||
if (arr[si] < piv) { | ||
si++; | ||
} else if (arr[ei] > piv) { | ||
ei--; | ||
} else { | ||
arr[si] = (arr[ei] + arr[si]) - (arr[ei--] = arr[si++]); | ||
} | ||
} | ||
return pid; | ||
} | ||
|
||
public static void quickSort(int[] arr, int si, int ei) { | ||
if (si < ei) { | ||
int p = partition(arr, si, ei); | ||
quickSort(arr, si, p - 1); | ||
quickSort(arr, p + 1, ei); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in).useDelimiter(","); | ||
System.out.println("Hint: Enter Array -> 1,2,3,4,5,6 "); | ||
System.out.print("Enter Array -> "); | ||
String input = sc.nextLine(); | ||
String[] split = input.split(","); | ||
int[] arr = new int[split.length]; | ||
for (int i = 0; i < split.length; i++) { | ||
arr[i] = Integer.parseInt(split[i]); | ||
} | ||
quickSort(arr, 0, arr.length - 1); | ||
System.out.println("Sorted Array -> " + Arrays.toString(arr)); | ||
sc.close(); | ||
} | ||
} |
Oops, something went wrong.