I need to sort a point array (a point is a struct with two float
types - one for x
and one for y
) in a special fashion.
The points have to be sorted so when they are traversed, they form a zig-zag pattern starting at the top leftmost point, moving to the top rightmost point, then down to the second leftmost point, to the second rightmost point and so on.
I need this to be able to convert arbitrary polygons to triangle strip arrays which I can then draw using GLes. What would be the most efficient way of sorting those points, by either using pointers (ie. passing and rearranging the pointers to the point structures) or by copying and moving the data in the structures directly?
Quicksort. Quicksort is generally thought of as the most efficient 'general' sorting algorithm, where nothing is known about the inputs to the array, and it's more efficient than insertion sort on large lists.
Quicksort. Quicksort is one of the most efficient sorting algorithms, and this makes of it one of the most used as well. The first thing to do is to select a pivot number, this number will separate the data, on its left are the numbers smaller than it and the greater numbers on the right.
Example: Sort an Array in Java in Ascending Order Then, you should use the Arrays. sort() method to sort it. That's how you can sort an array in Java in ascending order using the Arrays. sort() method.
Many sorting algorithms are available, but the one which is best suited for the almost sorted array is the insertion sort.
Basic C programming, Array, Functions, Pointers, Function Pointers Logic to sort an array using pointers Below is the step by step descriptive logic to sort an array using pointer. Input size and elements in array. Store them in some variable say sizeand arr.
This c program will sort the given array in ascending order by passing the array pointer to functions and the while loop for sorting.
The algorithm is not efficient when compared to other modern sorting algorithms but its easy to understand and use. Program to sort an array using pointers /** * C program to sort an array using pointers.
The selection sort may be defined as another algorithm for sorting the list in which the array is bifurcated into two arrays where the first array is supposed to be empty while the second array consists of the unsorted list of values.
I'd use qsort() with a custom compare() function that as @stefan noted, sorts descending by y then alternates (max/min) for x.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With