sorting
-
hi.. i have an array of data i want to sort the data linearly..is there any way to do it..?
-
hi.. i have an array of data i want to sort the data linearly..is there any way to do it..?
Use
std::sort
from the STL. For example to sort an array ofint
s:int NumArray[] = {3, 1, 4, 1, 5, 9, 2, 6, 5}; int *pNumOnePartEnd = NumArray + sizeof(NumArray)/sizeof(NumArray[0]); std::sort(NumArray, pNumOnePartEnd);
Remember to#include <algorithm>
. Steve -
Use
std::sort
from the STL. For example to sort an array ofint
s:int NumArray[] = {3, 1, 4, 1, 5, 9, 2, 6, 5}; int *pNumOnePartEnd = NumArray + sizeof(NumArray)/sizeof(NumArray[0]); std::sort(NumArray, pNumOnePartEnd);
Remember to#include <algorithm>
. SteveStephen Hewitt wrote:
int NumArray[] = {3, 1, 4, 1, 5, 9, 2, 6, 5};
int *pNumOnePartEnd = NumArray + sizeof(NumArray)/sizeof(NumArray[0]);
std::sort(NumArray, pNumOnePartEnd);should probably be pNumOnePastEnd ;)
-
Stephen Hewitt wrote:
int NumArray[] = {3, 1, 4, 1, 5, 9, 2, 6, 5};
int *pNumOnePartEnd = NumArray + sizeof(NumArray)/sizeof(NumArray[0]);
std::sort(NumArray, pNumOnePartEnd);should probably be pNumOnePastEnd ;)
Yes, I did mean to write "one past the end". Note however that I made the mistake consistently so the example would still work. Steve