I have an unsorted linked list. I need to sort it by a certain field then return the linked list to its previous unsorted condition. How can I do this without making a copy of the list?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Taking your points in reverse order, to support returning to original order, you can add an extra
intfield to each list node. Set those values based on the original order, and when you need to return it to the original order, just sort on that field.As far as the sorting in general goes, you probably want to use something like a merge-sort or possibly a Quick-sort.