Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
AdarshAddee committed Oct 4, 2022
2 parents e9fb6e5 + 78a212d commit 04fec01
Show file tree
Hide file tree
Showing 14 changed files with 664 additions and 17 deletions.
61 changes: 61 additions & 0 deletions C++/Merge_sort.cpp
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);



}

18 changes: 18 additions & 0 deletions C++/Power_of_2.cpp
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;
}
17 changes: 17 additions & 0 deletions C++/factorialprogram.cpp
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);

}
40 changes: 40 additions & 0 deletions C/BubbleSort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// PradeepKhatri - https://github.com/PradeepKhatri

#include <stdio.h>

void printArray(int *A,int n)
{
for(int i=0;i<n;i++)
{
printf("%d ",A[i]);
}
printf("\n");
}

void BubbleSort(int *A,int n)
{
int temp;
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(A[j] > A[j+1])
{
temp = A[j];
A[j] = A[j+1];
A[j+1] = temp;
}
}
}
}

int main()
{
int A[] = {5,7,3,1,2};
int n = 5;
printArray(A,n);
BubbleSort(A,n);
printArray(A,n);

}

56 changes: 56 additions & 0 deletions C/selection_sort.c
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;
}
24 changes: 22 additions & 2 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
| Khushi Marothi | <a href="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/khushimarothi">Khushi Marothi</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Aditya Giri | <a href="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/aditya-464">Aditya Giri</a> | <a href="mailto:[email protected]">E-Mail</a> |
| KryPtoN | <a href="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/Kry9toN">Kry9toN</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Udyansingh | <a href="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/Udyansingh">Udyan Singh</a> | <a href="[email protected]">E-Mail</a> |
| Hardik Pratap Singh | <a href="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/hardik-pratap-singh">Hardik Pratap Singh</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Suraj Bhandarkar S | <a href="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/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> |
Expand All @@ -28,8 +29,27 @@
| Aditya Wadkar | <a href="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/AdityaWadkar">Aditya Wadkar</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Rahul Jangle | <a href="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/Rronny01/">Ronny</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Anurag Vats | <a href="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/AnuragVats007">Anurag Vats</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Daksh Kesarwani | <a href="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/InnocentDaksh63">Daksh kesaarwani</a> | <a href="[email protected]">E-Mail</a> |
| Aritroo Chowdhury | <a href="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/aritroo">Aritroo Chowdhury</a> | <a href="[email protected]">E-Mail</a> |
| Daksh Kesarwani | <a href="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/InnocentDaksh63">Daksh kesaarwani</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Aritroo Chowdhury | <a href="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/aritroo">Aritroo Chowdhury</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Daksh Kesarwani | <a href="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/InnocentDaksh63">Daksh kesaarwani</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Kartikey Singh | <a href="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/kartik-ey1">Kartikey Singh</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Daksh Kesarwani | <a href="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/InnocentDaksh63">Daksh kesaarwani</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Pradeep Khatri | <a href="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/PradeepKhatri">Pradeep Khatri</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Apurva Dubey | <a href="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/umbridge">umbridge</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Daksh Kesarwani | <a href="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/InnocentDaksh63">Daksh kesaarwani</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Chirag Chandnani | <a href="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/chiragchandnani10">Chirag Chandnani</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Shivam Jaiswal | <a href="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/Shivaminc">Shivam Jaiswal</a> | <a href="mailto:[email protected]">E-mail</a> |
| Ashish Kushwaha | <a href="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/AshishKingdom">Ashish Kushwaha</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Dhruv Arora | <a href="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/lord-benjamin">Dhruv Arora</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Tharindu Sooriyaarchchi | <a href="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/TharinduDilshan>Tharindu Sooriyaarchchi</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Samriddh Prasad | <a href="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/Samriddh2703">Samriddh Prasad</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Edgar Gonzalez | <a href="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/Edgarzerocool">Edgar Gonzalez</a> | <a href="mailto:[email protected]">E-Mail</a> |









Expand Down
7 changes: 7 additions & 0 deletions Dart/numbers.dart
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);
}
}
38 changes: 38 additions & 0 deletions Java/InsertionSort.java
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();
}
}
51 changes: 51 additions & 0 deletions Java/QuickSort.java
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();
}
}
Loading

0 comments on commit 04fec01

Please sign in to comment.