Control Array Population - Sorted

M

Mike Copeland

I have the following structure:

#define TLIMIT 5
typedef struct EntTimes
{
int bibNumber;
short numST, nunFT;
long startLine[TLIMIT];
long finishLine[TLIMIT];
string entName;
} eTWork;
eTWork eData;
typedef map<int, EntTimes> ETIMES;
ETIMES etr;
map<int, EntTimes>::iterator eTIter;

in which I wish to store ordered values in the "startLine" and
"finishLine" arrays. Specifically, I want to populate the "startLine"
array with values that are high-to-low and to populate the "finishLine"
array with values that are low-to-high. In all cases I will have one-
to-n values to be stored (but "n" may exceed the array limit).
I've tried to manually code something, but it's horribly convoluted
(and no doubt buggy). I suspect there's an STL function (queue?,
deque?) that may help me, but I can't seem to make sense of available
options. Please advise. TIA
 
I

Ian Collins

Mike said:
I have the following structure:

#define TLIMIT 5

Best to use a const rather than a macro in C++.
typedef struct EntTimes

Another spillover from C, just write "struct eTWork".
{
int bibNumber;
short numST, nunFT;
long startLine[TLIMIT];
long finishLine[TLIMIT];
string entName;
} eTWork;
eTWork eData;
typedef map<int, EntTimes> ETIMES;

All caps tends to be reserved for macros, using it for types may confuse
readers.
ETIMES etr;
map<int, EntTimes>::iterator eTIter;

in which I wish to store ordered values in the "startLine" and
"finishLine" arrays. Specifically, I want to populate the "startLine"
array with values that are high-to-low and to populate the "finishLine"
array with values that are low-to-high. In all cases I will have one-
to-n values to be stored (but "n" may exceed the array limit).
I've tried to manually code something, but it's horribly convoluted
(and no doubt buggy). I suspect there's an STL function (queue?,
deque?) that may help me, but I can't seem to make sense of available
options. Please advise. TIA

Look up std::set.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top