User Profile
Collapse
-
Right, but the point we were discussing before was that if you have a simple data type, it would be faster and simpler to just swap out the values of the nodes. -
-
Ah, so you're saying that it might be faster to swap the pointers around if the data stored in the linked list is a complex type like a class.Leave a comment:
-
What is the necessity of swapping the nodes themselves? While swapping the values isn't truly the same as swapping the nodes, the end result is the same without all the extra pointer assignments.
A check to see if a already equals b would save you a lot of time though.Leave a comment:
-
Assuming you can get pointers to the data of the two nodes you want to swap (call them a and b), I'd do the following:
- In your function, create a variable to temporarily hold the value of b (if you're using an int, int temp = b).
- Assign the value of a to the value of b (b = a).
- Assign the value of a to the temporary variable (a = temp).
Leave a comment:
No activity results to display
Show More
Leave a comment: