目前,我不担心效率,我只是在学习。我想知道是否有人可以帮助我学习一个简单的单链表插入排序。这是我的作业,所以我想了解它。这是代码:
char c[13];
r >> c;
r >> NumberOfInts;
Node *node = new Node;
head = node; //start of linked list
for(int i = 0; i < NumberOfInts; i++) //this reads from the file and works
{
r >> node->data;
cout << node->data << endl;
node ->next = new Node; //creates a new node
node = node->next;
if(_sortRead) //true
{
for(int k = 0; k < i; k++)
{
//insertion sort
}
}
}
到目前为止,我已将它读入 istream,因此我需要在读入时对其进行排序。节点是一个结构 btw。有人可以帮我吗?