C
cerr
Hi There,
I have no problem doing a bubble sort in an array but what if i need
to keep an identifier that is linked to the value so i always know
which values is where?
I have a little array with three "offset" elements and i would like to
sort them so that the smallest offset is at position 0. I can do that
with an array, n.p.:
// Bubble sort offset times
for (ctr=0;ctr<OFFSET_ARR_SZ;ctr++) {
if (iarray[ctr] > iarray[ctr+1]) {
//Here a swap is needed
temp=iarray[ctr+1];
iarray[ctr+1]=iarray[ctr];
iarray[ctr]=temp;
}
}
but once they're sorted and i want to take action i need to know what
action to take after the first offset i.e. i need to keep some kind of
identifier. I am aware that I could just sort after applying some kind
of binary mask to keep an id in my value... but i imagine there's a
more transparent way e.g. by sorting values in a structure...?
Recommendations and hints appreciated!
Thanks!
I have no problem doing a bubble sort in an array but what if i need
to keep an identifier that is linked to the value so i always know
which values is where?
I have a little array with three "offset" elements and i would like to
sort them so that the smallest offset is at position 0. I can do that
with an array, n.p.:
// Bubble sort offset times
for (ctr=0;ctr<OFFSET_ARR_SZ;ctr++) {
if (iarray[ctr] > iarray[ctr+1]) {
//Here a swap is needed
temp=iarray[ctr+1];
iarray[ctr+1]=iarray[ctr];
iarray[ctr]=temp;
}
}
but once they're sorted and i want to take action i need to know what
action to take after the first offset i.e. i need to keep some kind of
identifier. I am aware that I could just sort after applying some kind
of binary mask to keep an id in my value... but i imagine there's a
more transparent way e.g. by sorting values in a structure...?
Recommendations and hints appreciated!
Thanks!