✔ 最佳答案
// Headers and Macros
#ifndef _MSC_VER
#undef NULL
#define NULL 0
#endif
#include <iostream>
#include <cstdlib>
using namespace std;
//
#define ARRAY_NUMBER 5
#define ELE_PER_ARRAY 10
#include <vector>
#include <algorithm>
#include <functional>
typedef vector<int> Vint;
class CHW
{
public:
CHW(void)
{
this->BuildArray();
this->Process();
}
// Rule of Three in C++
// 1. Copy Constructor
CHW(CHW& clone){}
// 2. Copy Assignment Operator
CHW& operator=(CHW& clone)
{
if ( this != &clone ){}
return *this;
}
// 3. Destructor
~CHW()
{
if ( ! this->m_vint.empty() )
{
this->m_vint.clear();
}
}
void BuildArray(void)
{
for ( int I = 0; I < ARRAY_NUMBER; I ++)
{
for ( int J = 0; J < ELE_PER_ARRAY; J ++)
{
this->m_pNum[I][J] = I * 10 + J;
}
}
for ( int I = 0; I < ARRAY_NUMBER; I ++)
{
for ( int J = 0; J < ELE_PER_ARRAY; J ++)
{
cout<<" "<<this->m_pNum[I][J];
}
cout<<endl;
}
}
void Process(void)
{
for ( int I = 0; I < ARRAY_NUMBER; I ++)
{
for ( int J = 0; J < ELE_PER_ARRAY; J ++)
{
this->m_vint.push_back(this->m_pNum[I][J]);
}
}
cout<<endl<<"Before sort..."<<endl;
for ( Vint::iterator it = this->m_vint.begin(); it != this->m_vint.end(); it ++)
{
cout<<" "<<(*it);
}
cout<<endl<<"After sort..."<<endl;
sort( this->m_vint.begin(), this->m_vint.end(), greater<int>());
for ( Vint::iterator it = this->m_vint.begin(); it != this->m_vint.end(); it ++)
{
cout<<" "<<(*it);
}
cout<<endl;
}
private:
int m_pNum[ARRAY_NUMBER][ELE_PER_ARRAY];
Vint m_vint;
};
//Main Function
#ifndef _MSC_VER
int
#else
void
#endif
main(int argc, char** argv)
{
//==START==//
CHW a;
//==END==//
system("PAUSE");
return
#ifndef _MSC_VER
EXIT_SUCCESS
#endif
;
}
2009-11-19 18:35:30 補充:
哪邊出錯了?
動態陣列、STL 應該沒錯吧!
2009-11-20 16:22:27 補充:
=__=!
又不是大型程式…,可以執行就好啦!