by Sarah » Thu Oct 12, 2017 2:02 am
For suggestion 1, I'm a bit surprised this isn't already possible. If I'm stuck with just arrays, Z-Windows will need this in order to process groups of elements; from reading the page on pointers it doesn't appear I can create linked lists which is a bit of a downer. Be nice to have this and actual *pointers.
This page gives a nice overview of the various sorting methods out there. My vote would be on a merge sort as the time complexity seems to remain fairly constant with large arrays. Basically sorting often results in O(n^2) for a worst case scenario regardless of algorithm. I think what I would do, if I knew my arrays were likely to contain thousands of items, I would implement some sort of pre-sorting as part of array insertion.
Counting occurrences is probably doomed to be a linear method. If you could pass the array into a method it wouldn't be hard to implement in your own code.
For suggestion 1, I'm a bit surprised this isn't already possible. If I'm stuck with just arrays, Z-Windows will need this in order to process groups of elements; from reading the page on pointers it doesn't appear I can create linked lists which is a bit of a downer. Be nice to have this and actual *pointers.
[url=https://codereview.stackexchange.com/questions/87085/simple-comparison-of-sorting-algorithms-in-c]This page[/url] gives a nice overview of the various sorting methods out there. My vote would be on a merge sort as the time complexity seems to remain fairly constant with large arrays. Basically sorting often results in O(n^2) for a worst case scenario regardless of algorithm. I think what I would do, if I knew my arrays were likely to contain thousands of items, I would implement some sort of pre-sorting as part of array insertion.
Counting occurrences is probably doomed to be a linear method. If you could pass the array into a method it wouldn't be hard to implement in your own code.