Sunday, November 22, 2015

Nah kali ini gua bakal bahas tentang kodingan count sort !!!

Kurang lebihnya mohon maaf sok we di  simak ^__^
#include <iostream>
#include <conio.h>

using namespace std;
int bil[99], f, k, A[99];

void input();
void output();
void dsc();
void asc();

int main()
{
    cout << "masukkan jumlah array: ";
    cin>>f;
    for (int x=0;x<99;x++){
        A[x]=0;
    }
    input();
    output();
    dsc();
    asc();
}

void input(){
    for (int x=0;x<f;x++){
        cout<< "Angka ke - "<<x+1<< " :";
        cin>>bil[x];
    }
}
void output(){
    cout<< "\nData sebelum di sorting : ";
    for (int x=0;x<f;x++){
        cout<< bil[x]<< " ";
    }
}
void dsc(){
    cout<< "\n\nData setelah di sorting  : ";
    for (int x=0;x<99;x++){
        A[x]=0;
    }

    for (int x=0;x<f;x++){
        A[bil[x]]++;
    }

    int b=0;

    for (int x=0;x<99;x++){
        while (A[x]>0){
            bil[b++] = x;
            A[x]--;
        }
    }
    for (int x=f-1;x>=0;x--){
        cout<< bil[x]<< " ";
    }
}
void asc(){
    cout<< "\nData setelah di sorting  : ";
    for (int x=0;x<f;x++){
        A[bil[x]]++;
    }

    int b=0;

    for (int x=0;x<99;x++){
        while (A[x]>0){
            bil[b++] = x;
            A[x]--;
        }
    }
    for (int x=0;x<f;x++){
        cout<< bil[x]<< " ";
    }
}

Nah ini adalah hasil kodingannya !!



{ 1 komentar... read them below or add one }

- Copyright © NonameBLOG - Blogger Templates - Powered by Blogger - Designed by Johanes Djogan -