Contoh program c++ sorting lengkap

Nah kali ini saya akan share contoh program c++ sorting lengkap sederhana, semoga apa yang kami share selalu bermanfaat bagi anda semua.

 #include <iostream>
#include <string.h>

#include <windows.h>

using namespace std;


void gotoxy (int x, int y)

{

    COORD coord = {0, 0};

    coord.X = x; coord.Y = y;

    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}


void head ()

{

 system ("cls");

    gotoxy (20, 1);

    cout<<"===PROGRAM MENGURUTKAN NAMA DARI A-Z===\n";

    cout<<"_______________________________________________________________________________\n\n";

}


main ()

{

    int  jumlah, a, j, k, m, y, z;

 char kata[100][40], sementara[40], pilih;


 system("cls");

 head();


 cout<<"\nMasukan jumlah nama (max 100) = ";

 cin>>jumlah;


    for (z=1; z<=jumlah; z++)

     {

        cout<<"\nInput nama ke-" <<z <<"= ";

  cin>>kata[z];


        if (z>1)

        {

           for (j=1; j<=z; j++)

           {

               a=strcmp(kata[z], kata[j]);

           

               if (a<=0)

               {

                  strcpy (sementara, kata[z]);

             

                  for (k=z; k>=j; k--)

                  {

                      m=k+1;

                      strcpy (kata[m], kata[k]);

                  }

             

                  strcpy (kata[j], sementara);

               }

           }

        }

    }


 system("cls");

 head();


 cout<<"\n\nHasil pengurutan nama (dari A-Z) : \n\n";


    cout<<"________________________________\n";

 gotoxy (1, 9);

    cout<<"No.\t|\tNama\t\t|\n";

    cout<<"________________________________";


    gotoxy (0, 12);

    for (z=1; z<=jumlah; z++)

    {

  cout<<z <<".\t|\t" <<kata[z] <<"\t\t|\n\n";

    }


    cout<<"________________________________\n\n";


    cout<<"Ingin kembali ke awal [y/t]? ";

    cin>>pilih;


    if (pilih=='y')

    {


  main();

 }

 else

 {

  system ("cls");

 }

} 
Default image
Team Program
Full Time Blogger, Writing, Freelancer Professional, Web Development

Leave a Reply