_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › 曙

Contents

1 蠍磯蓋蟲
2 る谿, 企殊姶


1 蠍磯蓋蟲 #

#include <stdio.h>
#include <stdlib.h>

void insert_sort(int*, int);

int main(int argc, char *argv[])
{
    int i;
    int A[10] = {7,3,4,1,8,9,0,5,2,6};
    
    insert_sort(A, sizeof(A)/4);  
    
    for(i = 0; i < sizeof(A)/4; i++)
    {
        printf("A[%d] = %d\n", i, A[i]);
    }
    
    system("PAUSE");	
    return 0;
}

void insert_sort(int* data, int size)
{
    int i,j,temp;
   
    for(i = 1; i < size; i++)
    {
        for(j = i; j > 0; j--)
        {
            if (data[j] < data[j-1])
            {
                temp = data[j];
                data[j] = data[j-1];
                data[j-1] = temp;
            }
        }
    }
}
for襭螳 2螳蟾 O2 螻襴讀企れ.

2 る谿, 企殊姶 #

#include <stdio.h>
#include <stdlib.h>

int insert_sort(int*, int, char*);

int main(int argc, char *argv[])
{
    int i,size;
    int A[10] = {7,3,4,1,8,9,0,5,2,6};
    size = sizeof(A)/sizeof(int);
    
    //insert_sort(A, size, "asc");  
    //insert_sort(A, size, "desc"); 
    
    if (!insert_sort(A, size, "desc"))
    {
        for(i = 0; i < size; i++)
        {
            printf("A[%d] = %d\n", i, A[i]);
        }
    }
    system("PAUSE");	
    return 0;
}

int insert_sort(int* data, int size, char* order)
{
    int i,j,temp;
    
    if (size <= 1)
       return 0;
    if ("asc" == order)
    { 
        for(i = 1; i < size; i++)
        {
            for(j = i; j > 0; j--)
            {
    
                if (data[j] < data[j-1])
                {
                    temp = data[j];
                    data[j] = data[j-1];
                    data[j-1] = temp;
                }
            }
        }
    }
    else if ("desc" == order)
    {
        for(i = 1; i < size; i++)
        {
            for(j = i; j > 0; j--)
            {
    
                if (data[j] > data[j-1])
                {
                    temp = data[j];
                    data[j] = data[j-1];
                    data[j-1] = temp;
                }
            }
        }
    }
    else
        return 1;
        
    return 0;
}

る谿, 企殊姶手 if螳 れ願給. 一一襯 "<" ">"襦襷 覦蠑碁 襷伎. 譬 覦覯? 讒..
蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:52

螻殊れ 語伎 る 蟆企 襷 覦 煙る所 覩碁リ 蠍一 襷豢 讌る蟆 . (伎螻)