コード例 #1
0
ファイル: ListCtrlEx.cpp プロジェクト: albertzeng/eRadQueue
int CListCtrlEx::Partition(int nFirst, int nLast)
{
	CString strThis, strMiddle;

	int nColumn = this->m_pColumnMap[abs(this->m_nSortColumn) - 1] - 1;

	int nLow = nFirst - 1;
	int nHigh = nLast + 1;
	strMiddle = GetItemText(nFirst, nColumn);

	while (nLow < nHigh)
	{
		do
		{
			nHigh--;
			strThis = GetItemText(nHigh, nColumn);
		} while (CompareBy(strThis, strMiddle));

		do
		{
			nLow++;
			strThis = GetItemText(nLow, nColumn);
		} while (CompareBy(strMiddle, strThis));

		if (nLow < nHigh)
			SwapRow(nLow, nHigh);
	}

	return nHigh;
}
コード例 #2
0
void CTWenUGCtrlEx::Sort_ByNumber(bool emptyFirst, int col, long rowFrom, long rowTo, long rowHead)
{/*
	CUGCell cell;
	GetCell(col,rowHead, &cell); 
	cell.SetCellType(UGCT_ARROW); 
	cell.SetCellTypeEx(UGCT_ARROWDRIGHT); 
	SetCell(col, rowHead, &cell);//*/

	for(long i=rowFrom; i<=rowTo; i++)
	{
		long index = RowIndexOfMinValue(emptyFirst, col, i, rowTo);
		if(index != i) SwapRow(i, index);
	}
}
コード例 #3
0
YSRESULT YsMatrix::Invert(void)
{
	YsMatrix sync;

	sync.Create(nRow,nColumn);
	sync.LoadIdentity();

	int n,r;
	double a;
	for(n=1; n<=nColumn; n++)
	{
		// Sweep Out Column n
		for(r=n+1; r<=nRow; r++)
		{
			if(YsAbs(v(n,n))<YsAbs(v(r,n)))
			{
				SwapRow(r,n);
				sync.SwapRow(r,n);
			}
		}

		a=v(n,n);
		if(YsAbs(a)>=YsTolerance)
		{
			DivRow(n,a);
			sync.DivRow(n,a);

			for(r=1; r<=nRow; r++)
			{
				if(r!=n)
				{
					a=v(r,n);
					Row1MinusRow2Mul(r,n,a);
					sync.Row1MinusRow2Mul(r,n,a);
				}
			}
		}
		else
		{
			return YSERR;
		}
	}
	*this=sync;

	return YSOK;
}
コード例 #4
0
/*带列主元的高斯消去法解方程组,最后的解在matrixA的对角线上*/
bool GuassEquation::Resolve(std::vector<double>& xValue)
{
    assert(xValue.size() == m_DIM);

    /*消元,得到上三角阵*/
    for(int i = 0; i < m_DIM - 1; i++)
    {
        /*按列选主元*/
        int pivotRow = SelectPivotalElement(i);
        if(pivotRow != i)/*如果有必要,交换行*/
        {
            SwapRow(i, pivotRow);
        }
        if(IsPrecisionZero(m_matrixA[i * m_DIM + i])) /*主元是0? 不存在唯一解*/
        {
            return false;
        }
        /*对系数归一化处理,使行第一个系数是1.0*/
        SimplePivotalRow(i, i);
        /*逐行进行消元*/
        for(int j = i + 1; j < m_DIM; j++)
        {
            RowElimination(i, j, i);
        }
    }
    /*回代求解*/
    m_matrixA[(m_DIM - 1) * m_DIM + m_DIM - 1] = m_bVal[m_DIM - 1] / m_matrixA[(m_DIM - 1) * m_DIM + m_DIM - 1];
    for(int i = m_DIM - 2; i >= 0; i--)
    {
        double totalCof = 0.0;
        for(int j = i + 1; j < m_DIM; j++)
        {
            totalCof += m_matrixA[i * m_DIM + j] * m_matrixA[j * m_DIM + j];
        }
        m_matrixA[i * m_DIM + i] = (m_bVal[i] - totalCof) / m_matrixA[i * m_DIM + i];
    }

    /*将对角线元素的解逐个存入解向量*/
    for(int i = 0; i < m_DIM; i++)
    {
        xValue[i] = m_matrixA[i * m_DIM + i];
    }

    return true;
}