关于List的复杂问题

laolaoliu2002 laolaoliu2002 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#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下编译完后程序运行效率相差很大为什么??
...全文
评论 4
收藏 已收藏
分享
返回顶部
laolaoliu2002
C++ 语言 65,214 成员 250,514 内容