getNode():
Node<type> getNode(int position) {
Node<type> *item = head;
for (int i = 0; i < position; ++i) {
item = item->next;
}
return *item;
};
Node Swapping Code:
Node<Guitar*> temp;
temp.element = list.getNode(l).element;
temp.next = list.getNode(l).next;
list.getNode(l).element = list.getNode(h).element;
list.getNode(l).next = list.getNode(h).next;
list.getNode(h).element = temp.element;
list.getNode(h).next = temp.next;
I am working on a project for my computer science class and it is due in a couple of days. I want to sort a linked list using quicksort which is fairly simple, but I have been struggling with a strange issue while swapping nodes in the list. For reference, the getNode() function returns a node at a certain index in the list and the nodes hold a pointer to a guitar object along with the a next node pointer. I have been experimenting for hours now and I figured out that the line such as this, "list.getNode(h).element = temp.element;" is saying that the pointer to a guitar object in a node in the list is being assigned the value of the pointer in the temp object. This would normally work but I get an error at this point saying that the left side is not a modifiable lvalue. However I could make a pointer and put it on the left side of the assignment operator without any errors. Also, the left hand side has no error when I use the dereferencing operator (*) in front, but this does not successfully swap the nodes. I must be missing something.