facebook pixel

Program Insertion Sorting Array C++

Program Insertion Sorting Array C++ – Hai sobat IT TECH ketemu lg dengan saya .
Kali ini saya akan memberikan sedikit ilmu yang telah saya pelajari di kampus, bagaimana cara membuat salah satu program C++ yaitu Program Insertion Sorting Array, Yang Saya Compile Dengan Compiler CodeBlocks.

Langsung saja berikut codingannya : 

#include <iostream>
using namespace std;
int A[]={2,6,3,1,8,3,9,4,5,2};
int n =10;
void selectionsort_ascend()
{
    int i,temp,j,imax;
    for (i=0;i<n-1;i++)
    {   imax =i;
        for (j=i+1;j<n;j++)
          {
              if (A[imax] > A[j]) //Untuk Ascending atau descending tinggal Ubah Tanda “>” atau “<”
              {
                  imax = j;
              }
          }
        temp  = A[i];
        A[i]  = A[imax];
        A[imax]= temp;
    }
}
void show()
{
    for (int i=0;i<n;i++)
    {
        cout<<A[i]<<” “;
    }
}
int main()
{
    cout<<“nPROGRAM INSERTION SORT n”;
    cout<<“nData Sebelum Terurut = “;
    show();  cout<<endl;
    selectionsort_ascend();
    cout<<“nnData Sesudah Terurut = “;
    show();
    cout<<endl;
    return 0;
}

Berikut output programnya :

Semoga Bermanfaat.

#OnBlog

Tinggalkan Komentar

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *