当谈到C++时,我是世界上最基本的人,我想知道如果你们能帮我解决问题,那么你们是否可以帮助我。我试图对读取到istream的节点进行排序,但是它们是在读入的。网络上的代码非常复杂,我想知道是否有一个非常基本的方法来实现这一点。当插入到istream中时,对单个链表进行排序C++
这是我读法,至今它读入这是伟大的istream的,但现在我需要将其排序为在读。我的头好痛哈哈
void ListClass::Read(istream& r)
{
char c[13];
r >> c;
r >> numberOfInts;
Node *node = new Node();
head = node;
for(int i = 0; i < numberOfInts; i++)
{
r >> node->data;
cout << node->data << endl;
node->next = new Node;
node = node->next;
}
}
,这里是我的节点类我的头文件
class Node
{
public:
Node() {} //default constructor
Node(int d, Node* q = 0) : data(d), next(q) {} //constructor with parameters data and next
int data; //holds data in node
Node* next;//pointer to next node
};
您遇到的方法(“网上的代码”)是什么? (只是为了避免人们向你推荐同样的东西) – jonsca 2011-04-27 13:22:04
其中一个是模板方法,另一个更适合双链表和其他几个人,但即使是解释它的人也会感到困惑。基本上我正在寻找某种插入排序我想,但是在寻找它的时候,除非过于复杂,否则没有太多的东西 –
2011-04-27 13:24:09
@jonsca对不起忘了标记 – 2011-04-27 13:25:00