×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

c++ guys come to crab the code

class Data1
{
int i;
char c[4];
};
class Data2
{
int i;
char d[5];
double dd;
};
template <typename T> class TableObject
{
public:
list<T*> links;
typename list<T*>::iterator ite;
TableObject(){
//do insert Data1 or Data2 into links
}
~TableObject(){}

void Sort(){
ite=links.begin();
int i=0;
while ((ite+i)<links.end()){
if (*(ite+i).i>*(ite+i+1).i) //<-it seems impossible work
iter_swap((ite+i),(ite+i+1))
}
i++;
}
}
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / c++ guys come to crab the code
    class Data1
    {
    int i;
    char c[4];
    };
    class Data2
    {
    int i;
    char d[5];
    double dd;
    };
    template <typename T> class TableObject
    {
    public:
    list<T*> links;
    typename list<T*>::iterator ite;
    TableObject(){
    //do insert Data1 or Data2 into links
    }
    ~TableObject(){}

    void Sort(){
    ite=links.begin();
    int i=0;
    while ((ite+i)<links.end()){
    if (*(ite+i).i>*(ite+i+1).i) //<-it seems impossible work
    iter_swap((ite+i),(ite+i+1))
    }
    i++;
    }
    }
    • if (*(ite+i).i>*(ite+i+1).i) //<-it seems impossible work => if (*(ite+i)->i>*(ite+i+1)->i)
      • right, another issue is std::list::iterator is not random access, but bi-directional. only can be it++ or it--