10
八月

暑修資料結構 程式 08/10: ex2.c

   Posted by: admin   in 104(暑)資料結構

#include <stdio.h>
int main()
{
    int iData[10]={12, 5, 7, 16, 13, 19, 6, 18, 4, 11};
    int i,j, tt;
    for (i=0; i<10; i++)
       printf("%2d ", iData[i]);
    printf("\n");
    for (i=9; i>0; i--)
    {
        for (j=1; j <=i; j++)
        {
            if (iData[j-1] > iData[j])
            {
                tt = iData[j-1];
                iData[j-1] = iData[j];
                iData[j] = tt;
            }
        }
        for (j=0; j<10; j++)
             printf("%2d ", iData[j]);
        printf("\n");
    }
 
    return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

This entry was posted on 星期一, 八月 10th, 2015 at 03:31:58 and is filed under 104(暑)資料結構. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment