问题描述
- 怎么用c++写 二维数组 的旋转
-
我是新手 想用c++编写一个可以旋转的二维数组 但不知道怎么写 能不能给我讲一下或者告诉我那些书中可以学习 谢谢
解决方案
http://blog.csdn.net/edcvf3/article/details/7726422
http://www.cppblog.com/flyinghearts/archive/2010/12/23/137331.html
http://blog.sina.com.cn/s/blog_4aab244f0100ia08.html
解决方案二:
二维数组旋转
解决方案三:
什么叫做可旋转?就是数组反转么?
解决方案四:
下面是个模版类:
template<class T, int row=0, int column=0>
class CMyArray
{
public:
CMyArray()
:m_pData(NULL)
,m_nRow(row)
,m_nColumn(column)
{
if ( m_nRow>0 && m_nColumn>0 )
Allocate();
}
~CMyArray()
{
Free();
}
bool Resize(const int nRow, const int nColumn)
{
if ( nRow<=0 || nColumn<=0 )
return false;
m_nRow = nRow;
m_nColumn = nColumn;
Allocate();
return true;
}
T GetAt(const int nRow, const int nColumn)
{
if ( nRow>=m_nRow || nColumn>=m_nColumn )
return T();
return *(m_pData+nRow*m_nColumn+nColumn);
}
void SetAt(const int nRow, const int nColumn, const T& data)
{
if ( nRow>=m_nRow || nColumn>=m_nColumn )
return ;
*(m_pData+nRow*m_nColumn+nColumn) = data;
}
protected:
void Allocate()
{
Free();
m_pData = (T*)malloc(m_nRow*m_nColumn*sizeof(T));
}
void Free()
{
if ( m_pData )
{
free(m_pData);
m_pData = NULL;
}
}
private:
T* m_pData;
int m_nRow;
int m_nColumn;
};
矩阵旋转就参照百度知道的数学关系写一下就行:
矩阵旋转
解决方案六:
不太清楚旋转的具体要求,是90度还是180度,逆时针还是顺时针
时间: 2024-09-17 04:11:52