Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions SortingAlgorithms/C++/Bubble_Sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
using namespace std;

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

int main(){
int n;
cout<<"Enter the number of elements: ";
cin>>n;
int a[n];
cout<<"Enter the elements: ";

for(int i=0;i<n;i++){
cin>>a[i];
}

bubble_sort(a,n);

cout<<"Sorted array: ";
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
cout<<endl;

return 0;
}
36 changes: 36 additions & 0 deletions hackerrank/Aray/ArraysIntroduction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Arrays Introduction

You will be given an array of integers and you have to print the integers in the reverse order.

Sample Input

4
1 4 3 2

Sample Output

2 3 4 1

*/

#include <iostream>

using namespace std;


int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];

}
for(int i=n-1;i>=0;i--){
cout<<a[i]<<"\t";
}

return 0;
}