Skip to content

Commit

Permalink
Merge pull request #1 from Jr-Einstein/Jr-Einstein-patch-1
Browse files Browse the repository at this point in the history
Create Allsort.cpp
  • Loading branch information
Jr-Einstein authored Oct 17, 2024
2 parents 8e83255 + 4943cd8 commit 9e15e95
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Allsort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include<iostream>
using namespace std;

void selection_sort(int arr[],int n){
for(int i=0;i<=n-2;i++){
int mini = i;
for(int j=i;j<=n-1;j++){
if(arr[j] < arr[mini]){
mini = j;
}
}
int temp = arr[mini];
arr[mini]=arr[i];
arr[i]=temp;

}
}

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

void insertion_sort(int arr[], int n){
for(int i=0;i<=n-1;i++){
int j=i;
while(j>0 && arr[j-1]>arr[j]){
int temp = arr[j-1];
arr[j-1]=arr[j];
arr[j]=temp;

j--;
}
}
}

int main(){
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
selection_sort(arr,n);
bubble_sort(arr,n);
insertion_sort(arr,n);
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
return 0;


}

0 comments on commit 9e15e95

Please sign in to comment.