Help us understand the problem. What is going on with this article?

選択ソート

More than 3 years have passed since last update.

選択ソート…配列中の最小を選択して、それを左端の値と交換する。
例)53412
→13452
→12453
→12354
→12345

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

void SelectionSort();
void MakeArray();
void ShowData();
int main();

const int SIZE = 10;
int data[SIZE];


void MakeArray(){
    int i, num;
    srand((unsigned) time(NULL));

    for(i=0;i<SIZE;i++){
        num=rand()%900 + 100; //取得する値を100~999の間とする
        data[i] = num;
    }
}


void ShowData(){
    for(int i = 0; i < SIZE; i++){
        if(i != SIZE - 1){
            printf("%d, ", data[i]);
        }else{
            printf("%d", data[i]);
        }
    }
    printf("\n");
}

void SelectionSort(){
    int temp;
    int mini;
    int loop = SIZE - 1;

    for(int i = 0; i < loop; i++){
        mini = i;

        for(int j = i + 1;j < SIZE ;j++){
            if(data[j] < data[mini]){
                mini = j;
            }
        }

        if(mini != i){
            temp = data[i];
            data[i] = data[mini];
            data[mini] = temp;
        }
    ShowData();
    }
}

int main(){
    MakeArray();

    printf("(ソート前)\n");
    ShowData();

    SelectionSort();

    printf("(ソート後)\n");
    system("PAUSE");
    return 0;
    }
Simomo
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away