• Create Account

### #ActualRobot Ninja

Posted 11 October 2012 - 02:55 PM

If you want to implement sorting algorithms it's best to make sure you understand them completely so you can be sure they run as intended. It's very easy to make a sorting algorithm very inefficient by not implementing it correctly.

For string sorting you'll want to take a look at Radix Sort
For general purpose sorting you could take a look at Quicksort or Mergesort which are O(n log n) average case solutions which do not sort in-place, or Heapsort which can sort in-place.

Yes, you should get an understanding of some sorting algorithms first. If you can only use 1 singly linked list, then you would probably have to have functions to sort the names and health and then output it...BUT that's a terrible waste of cycles if you plan on outputting multiple times. What you should do is sort the data as it's being added to the list. So I wonder...

If you're looking for a more efficient method, then the Sorted list can't be a singly linked list.

+1 If you're using a linked list, but aren't restricted how many nodes you can keep track of, then what would be good in your case is if you had two pointers in your "HealthProfile" class (name it whatever you want, pointing to the node with the next name and the node with the next health score, respectively. Technically, the class would contain two singly linked lists inside of it - a double singly-linked list (lol). As you add data to the list, your class should be doing operations on each of those lists to keep them in order. Then when you want to output the names in order, you would iterate through the name nodes, and when you want to output the health scores in order, then you would iterate through the health nodes. Please let me know if you need clarification. I explain things in a confusing way sometimes, but it makes sense to me.

*EDIT* Sorry I used the term "pointer". C++ is my primary language, and I don't know what you work with.

### #1Robot Ninja

Posted 11 October 2012 - 02:54 PM

If you want to implement sorting algorithms it's best to make sure you understand them completely so you can be sure they run as intended. It's very easy to make a sorting algorithm very inefficient by not implementing it correctly.

For string sorting you'll want to take a look at Radix Sort
For general purpose sorting you could take a look at Quicksort or Mergesort which are O(n log n) average case solutions which do not sort in-place, or Heapsort which can sort in-place.

Yes, you should get an understanding of some sorting algorithms first. If you can only use 1 singly linked list, then you would probably have to have functions to sort the names and health and then output it...BUT that's a terrible waste of cycles if you plan on outputting multiple times. What you should do is sort the data as it's being added to the list. So I wonder...

If you're looking for a more efficient method, then the Sorted list can't be a singly linked list.

+1 If you're using a linked list, but aren't restricted how many nodes you can keep track of, then what would be good in your case is if you had two pointers in your "HealthProfile" class (name it whatever you want, pointing to the node with the next name and the node with the next health score, respectively. Technically, the class would contain two singly linked lists inside of it - a double singly-linked list (lol). As you add data to the list, your class should be doing operations on each of those lists to keep them in order. Then when you want to output the names in order, you would iterate through the name nodes, and when you want to output the health scores in order, then you would iterate through the health nodes. Please let me know if you need clarification. I explain things in a confusing way sometimes, but it makes sense to me.

PARTNERS