Wednesday, November 7, 2012

Sorting in c programming

Name : Sean Vandet
Major : D4 TMD ITB Batch 6
Sorting in c programming
Sorting used to mean simply as massaging a data in one data set that don't most massage.
Address is the location in memory where the value of the variable is stored.
Pinter is a variable whose value is also an address.

#include <stdio.h>
#include <stdlib.h>
void swapValue (int *tIntA, int *tIntB);

int main() {
    int tListAngka[20] = {1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2};
    int tSwap;
    int tUrutan;
    //repeat and check statement
    do {
        tSwap = 0;
        //repeat tUrutan = 1 end process when tUrutan = 18
        for(tUrutan=0;tUrutan<19;tUrutan++)
        {
            if(tListAngka[tUrutan] < tListAngka[tUrutan+1])
            {
                //one varaible has address and value
                swapValue(&tListAngka[tUrutan], &tListAngka[tUrutan+1]);
                tSwap = 1;
            }            
        }
    } while(tSwap == 1); //exit do()
    //repeat statement for loop
    for(tUrutan=0;tUrutan<20;tUrutan++)
    {
        //tUrutan 0 - 18

        printf("Nilai : %d\n", tListAngka[tUrutan],&tListAngka[tUrutan]);
    }
    system("pause");

}

void swapValue (int *tIntA, int *tIntB)
{
    int tInt = *tIntA;
    *tIntA = *tIntB;
    *tIntB = tInt;
}


link to youtube
http://www.youtube.com/watch?v=W_CURNVZkJQ&feature=youtu.be

No comments:

Post a Comment