当谈到 c++ 时,我是世界上最基本的人,我想知道你们是否可以帮助我,如果可以的话。我试图对读入 istream 的节点进行排序,但因为它们被读入。网络上的代码非常复杂,我想知道是否有一种非常基本的方法来实现这一点。
这是我的读取方法,到目前为止它读入 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
};