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源码分析list的sort()

上一篇:【leetcode】查找算法(顺序查找,二分法,斐波那契查找,插值查找,分块查找)


下一篇:我对老师的一点回忆(20211318)