root/SortStringArray.cpp

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. CSortStringArray
  2. CSortStringArray
  3. Sort
  4. Compare4Rearrange

/*
 * Copyright (C) 2002-2003 chik, s.hiranaka
 * For license terms, see the file COPYING in this directory.
 */

// SortStringArray.cpp: CSortStringArray クラスのインプリメンテーション
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Pochy.h"
#include "SortStringArray.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// 構築/消滅
//////////////////////////////////////////////////////////////////////

CSortStringArray::CSortStringArray()
{

}

CSortStringArray::~CSortStringArray()
{

}

void CSortStringArray::Sort()
{
        BOOL done = TRUE;

        while(done){
                done = FALSE;
                for(int pos = 0;pos < GetUpperBound();pos++)
                        done |= Compare4Rearrange(pos);
        }
}

BOOL CSortStringArray::Compare4Rearrange(int pos)
{
        CString temp;
        int first = pos;
        int next = pos+1;

        if(GetAt(first).CompareNoCase(GetAt(next)) > 0){
                temp = GetAt(first);
                SetAt(first, GetAt(next));
                SetAt(next, temp);
                return TRUE;
        }
        return FALSE;
}

/* [<][>][^][v][top][bottom][index][help] */