class SequentialList { public: SequentialList(void); //初始化 SequentialList(void) { m_BufLength = m_InitLength; m_pBuf = new T[m_BufLength]; m_Count = 0; } //增加一个元素 void Add(T item) { if(m_Count < m_BufLength) { m_pBuf[m_Count] = item; m_Count++; } else { T * temp = new T[m_BufLength + m_Increment]; for(int i = 0; i < m_Count; i++) { temp[i] = m_pBuf[i]; } temp[m_Count] = item; m_Count++; m_BufLength += m_Increment; delete[] m_pBuf; m_pBuf = temp; } } //析构 ~SequentialList(void) { if(m_pBuf != NULL) { delete[] m_pBuf; } m_Count = 0; m_BufLength = 0; } //排序 void SortAscending(void) { for(int i = 0; i < m_Count; i++) { for(int j = i + 1; j < m_Count;j++) { if(m_pBuf[i] > m_pBuf[j]) { T temp = m_pBuf[i]; m_pBuf[i] = m_pBuf[j]; m_pBuf[j] = temp; } } } } //显示函数 void Display(void) { for(int i = 0; i < m_Count; i++) { cout<<"["<<i<<"]"<<m_pBuf[i]<<endl; } } protected: static const int m_InitLength = 100;//初始化长度 static const int m_Increment = 10;//增量长度 int m_BufLength;//数组长度 int m_Count;//当前填充元素个数 T * m_pBuf;//缓冲区指针 };