stl源码分析list的sort()
作者:互联网
#include
#include
#include
typedef std::list IList;
void print(const IList& list)
{
IList::const_iterator it = list.begin();
for(; it != list.end(); ++it)
std::cout<<*it<<" ";
std::cout<<std::endl;
}
int main()
{
IList s;
s.push_back(5);
s.push_back(7);
s.push_back(6);
s.push_back(3);
s.push_back(2);
s.push_back(9);
s.push_back(1);
s.push_back(0);
s.push_back(4);
IList carry;
IList counter[64];
int fill = 0;
int num = 0;
while(!s.empty()) {
std::cout<<“取第”<<num<<“个数据:fill = “<<fill<<std::endl;
carry.splice(carry.begin(), s, s.begin());
while(i < fill && !counter[i].empty()) // 类似二进制,控制进位
{
couter[i].merge(carry);
carry.swap(counter[i++]);
}
carry.swap(counter[i]);
if(i == fill)
++fill;
num++; // 加的计数
for(int i = 0; i < fill; ++i)
{
std::cout<<“count[”<<i<<”]==”;
print(counter[i]);
}
// 最后将所有位的列表合并
for(int i = 1; i < fill; ++i)
counter[i].merge(counter[i - 1]);
s.swap(counter[fill - 1]);
for(auto & m: s)
cout<<m<<" ";
system(“pause”);
return 0;
}
标签:stl,counter,list,back,carry,源码,IList,push,fill 来源: https://blog.csdn.net/cchao985771161/article/details/92771282