Record File - 15jULY
Record File - 15jULY
• BUBBLE
• INSERTION
• SELECTION
#include<iostream>
using namespace std;
int main()
{
int n, i, arr[50], j, temp;
cout<<"Enter the Size (max. 50): ";
cin>>n;
cout<<"Enter "<<n<<" Numbers: ";
for(i=0; i<n; i++)
cin>>arr[i];
cout<<"\nSorUng the Array using Bubble Sort Technique..\n";
for(i=0; i<(n-1); i++)
{
for(j=0; j<(n-i-1); j++)
{
if(arr[j]>arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
cout<<"\nArray Sorted Successfully!\n";
cout<<"\nThe New Array is: \n";
for(i=0; i<n; i++)
cout<<arr[i]<<" ";
cout<<endl;
return 0;
}
INSERTION SORT
#include<iostream>
using namespace std;
void inSort(int a[], int n)
{
int i,j, k;
for (i = 1; i < n; i++)
{
k = a[i];
j = i - 1;
/*Move elements of arr[0..i-1], that are
greater than k, to one posiUon ahead
of their current posiUon */
while (j >= 0 && a[j] > k)
{
a[j + 1] = a[j];
j = j - 1;
}
a[j + 1] = k;
}
}
int main()
{
int a[] = { 15,2,8,7,3,5,4,1 };
int n = sizeof(a) / sizeof(a[0]);
inSort(a, n);
print(a, n);
return 0;
}
SELECTION SORT
#include<iostream>
using namespace std;