我希望程序重新排列从最小到最大的链表,但我继续得到"错误:左值作为赋值的左操作数"当我尝试制作prev->link()=temp;
和minum->link()=head_ptr;
node* previouse_minimum(node*& head_ptr){
node* cursor;
node* minimum;
node* prev;
minimum=head_ptr;
for(cursor=head_ptr; cursor != NULL; cursor=cursor->link())
if(cursor->data() < minimum->data())
minimum=cursor;
cursor = head_ptr;
prev = cursor;
while(cursor->link() != minimum)
{
cursor = cursor->link();
prev = cursor;
}
cout << prev->link()->data() << endl;
return prev;
}
void sort(node*& head_ptr, node*& marker_ptr)
{
node* print_ptr;
node* prev = previouse_minimum(head_ptr);
node* temp=NULL;
node* minum;
marker_ptr = head_ptr;
while(marker_ptr->link()->link()!= NULL)
{
minum = prev->link();
temp=minum->link();
prev->link()=temp;
minum->link()=head_ptr;
head_ptr=minum;
marker_ptr=minum->link();
prev=previouse_minimum(marker_ptr);
}
for(print_ptr = head_ptr; print_ptr !=NULL; print_ptr = print_ptr->link())
cout << print_ptr->data() << " ";
cout << endl;
}
答案 0 :(得分:0)
prev->link()
以及minum->link()
是返回节点的函数。您无法为函数指定值/指针。要设置节点,可以使用link()
等参数重载void link(node* input)
函数。