关于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下编译完后程序运行效率相差很大为什么??
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下编译完后程序运行效率相差很大为什么??
...全文
相关推荐
Jackson 框架 json 到 复杂 list 的转换
NULL 博文链接:https://bugyun.iteye.com/blog/2279033
【Flutter】 Flutter 实现 List Sort 排序 解决复杂业务逻辑下的数据排序问题
在 Flutter 中,List 是一种常用的数据结构,它可以存储一系列的数据。List 的排序是一个常见的需求,
Java8处理List的双层循环问题
主要介绍了Java8处理List的双层循环问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
Android-一个用于快速开发复杂List布局的框架
一个用于快速开发复杂List布局的框架
Python 多维List创建的问题小结
主要介绍了Python 多维List创建的问题小结,详细的介绍了遇到的一个小问题的解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下


