Khamis, 20 Oktober 2011

programming for sorting the name by C++

// you will change the amount of name by change the number of arrays
// by using codeblock
// enter 9 name in random and it will sort the name by alphabatical order...

// Place : Shah Alam,C++ class.
//From : _AlifAtif@DisTech_


#include <iostream>
//#include <string>


using namespace std;

int main ()
{

    string namelist [9];
    int r;
    int IPname=9;
    int iCv;
    string nTemp;


    for (r=1;r < IPname; ++r)

{
    cin >> namelist[r];
        //nTemp = namelist[];
    //the new value to be inserted into a temporary location
        nTemp = namelist[r];
    // k is the index of the number to the left of the iCv.
        int k;

        for (k = r-1; k >= 0 && namelist[k] > nTemp; k--)
        {
        namelist[k+1] = namelist[k];
        }
        namelist[k+1] = nTemp;
    }

for(r=1;r<IPname;r++)

cout<< namelist[r]<<endl;
    cout<<endl;

    return 0;
    }

0 ulasan:

Catat Ulasan