关于List的复杂问题
#include <vcl.h>
template <class T>
class UList :public TList
{
public:
inline __fastcall ~UList(){
while (Count >0)
{
delete (T*)Items[0];
Delete(0);
}
};
inline bool __fastcall AddItem(T * pValue){
Add((T*)pValue);
return true;
};
inline T * __fastcall GetItem(int aiIndex){
if(aiIndex < 0 || aiIndex >= Count)
return NULL;
return (T *)Items[aiIndex];
};
inline bool __fastcall DelItem(int aiIndex){
if ((aiIndex >= 0)&&(aiIndex < Count))
{
delete (T*)Items[aiIndex];
Delete(aiIndex);
return true;
}
return false;
};
inline void __fastcall ClearAllItem(){
while (Count >0)
{
delete (T*)Items[0];
Delete(0);
}
}
private:
};
#ifndef _SLIST_H
#define _SLIST_H
#include <list>
template<class T>
class CUCSlist
{
public:
std::list<T> mlist;
inline __fastcall ~CUCSlist()
{
if(!mlist.empty())
mlist.clear();
};
inline void __fastcall AddItem(const T&pValue)
{
mlist.push_back(pValue) ;
return ;
};
inline T __fastcall GetItem(int aiIndex)
{
std::list <T>::iterator llist_Iter;
int i=0;
for ( llist_Iter = mlist.begin( ); llist_Iter != mlist.end( ) && i <= mlist.size(); llist_Iter++,i++ )
if(i == aiIndex)
return *llist_Iter ;
};
inline bool __fastcall DelItem(int aiIndex)
{
if ((aiIndex >= 0)&&(aiIndex < mlist.size()))
{
std::list <T>::iterator llist_Iter;
int i=0;
for ( llist_Iter = mlist.begin(); llist_Iter != mlist.end( ) && i <= mlist.size(); llist_Iter++,i++)
if(i == aiIndex)
{
delete (*llist_Iter);
mlist.erase(llist_Iter);
break;
}
return true;
}
return false;
};
inline bool __fastcall Delete(int aiIndex)
{
if ((aiIndex >= 0)&&(aiIndex < mlist.size()))
{
std::list <T>::iterator llist_Iter;
int i=0;
for ( llist_Iter = mlist.begin(); llist_Iter != mlist.end( ) && i <= mlist.size(); llist_Iter++,i++)
if(i == aiIndex)
{
mlist.erase(llist_Iter);
break;
}
return true;
}
return false;
};
inline void __fastcall ClearAllItem()
{
while(!mlist.empty())
{
DelItem(0);
}
}
inline bool __fastcall Insert(int aiIndex, const T&pValue)
{
if (aiIndex > mlist.size())
{
mlist.push_back(pValue) ;
return true;
}else if(aiIndex == 0)
{
mlist.insert(mlist.begin(),pValue);
return true;
}
else if(aiIndex > 0)
{
std::list <T>::iterator llist_Iter;
int i=0;
for ( llist_Iter = mlist.begin(); llist_Iter != mlist.end( ) && i <= mlist.size(); llist_Iter++,i++)
if(i == aiIndex)
{
mlist.insert(llist_Iter,pValue);
return true;
}
}
return false;
}
inline int __fastcall size()
{
return mlist.size();
}
};
在BCB下编译完后程序运行效率相差很大为什么??