关于List的复杂问题

laolaoliu2002 2005-07-26 02:32:45
#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下编译完后程序运行效率相差很大为什么??
...全文
136 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
laolaoliu2002 2005-08-02
  • 打赏
  • 举报
回复
谁能解释一下BCB中LIST的具体实现,在那里进行了优化?
laolaoliu2002 2005-08-01
  • 打赏
  • 举报
回复
原因我已经找出来了,呵呵.不知道为什么回答的人比较少?
hzhxxx 2005-07-26
  • 打赏
  • 举报
回复

建议用 stdLL;:list
oyljerry 2005-07-26
  • 打赏
  • 举报
回复
相差很大?什么

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧