HIRASE CONNECTION WK

programming collection

目次

Blog 利用状況

ニュース

書庫

日記カテゴリ

Link Collection

[C++] バブルソート

バブルソート(Bubble sort)

2つの要素を比べては交換、比べては交換して、交換できる要素がなくなれば終了。同じ要素の並びは変わらない安定ソート。

template <typename TElement, typename TSize>
void BubbleSort(TElement * data, const TSize size)
{
    bool swapped = false;
    do
    {
        swapped = false;
        const TSize max = size - 1;
        for (TSize i = 0; i < max; ++i)
        {
            TElement diff = data[i] - data[i+1];
            if (diff > 0)
            {
                data[i  ] = data[i+1];
                data[i+1] = diff + data[i];
                swapped = true;
            }
        }
    } while (swapped);
}

これでOK?

交換するコードが、味噌味。

投稿日時 : 2008年5月7日 23:34

コメントを追加

# May I simply say what a relief to discover someone who genuinely knows what they're discussing over the internet. You definitely understand how to bring a problem to light and make it important. A lot more people should look at this and understand this 2019/04/10 8:54 May I simply say what a relief to discover someone

May I simply say what a relief to discover someone who genuinely knows what they're discussing over the internet.

You definitely understand how to bring a problem to light
and make it important. A lot more people should look at this and understand this side of your story.
It's surprising you aren't more popular because you surely possess the gift.

# We are a group of volunteers and starting a new scheme in our community. Your website provided us with valuable info to work on. You've done an impressive job and our whole community will be grateful to you. 2019/06/16 23:01 We are a group of volunteers and starting a new sc

We are a group of volunteers and starting a new scheme in our community.
Your website provided us with valuable info to work
on. You've done an impressive job and our whole community will be
grateful to you.

# Fantastic site. Plenty of useful information here. I'm sending it to some buddies ans additionally sharing in delicious. And obviously, thanks to your effort! 2019/09/04 10:52 Fantastic site. Plenty of useful information here.

Fantastic site. Plenty of useful information here. I'm sending it to some buddies ans additionally sharing
in delicious. And obviously, thanks to your effort!

# Fantastic site. Plenty of useful information here. I'm sending it to some buddies ans additionally sharing in delicious. And obviously, thanks to your effort! 2019/09/04 10:53 Fantastic site. Plenty of useful information here.

Fantastic site. Plenty of useful information here. I'm sending it to some buddies ans additionally sharing
in delicious. And obviously, thanks to your effort!

# Fantastic site. Plenty of useful information here. I'm sending it to some buddies ans additionally sharing in delicious. And obviously, thanks to your effort! 2019/09/04 10:54 Fantastic site. Plenty of useful information here.

Fantastic site. Plenty of useful information here. I'm sending it to some buddies ans additionally sharing
in delicious. And obviously, thanks to your effort!

# Fantastic site. Plenty of useful information here. I'm sending it to some buddies ans additionally sharing in delicious. And obviously, thanks to your effort! 2019/09/04 10:55 Fantastic site. Plenty of useful information here.

Fantastic site. Plenty of useful information here. I'm sending it to some buddies ans additionally sharing
in delicious. And obviously, thanks to your effort!

タイトル
名前
URL
コメント