0

I have a structure type like the one shown below, I use it to store the output of my program and these structures are stored in a structure vector.
Now I would like to print out the structures stored in the vector in ascending order of int Time_IF.

struct Input
{
 int Inst;
 string Instline;
 string DestReg;
 string InputReg1;
 string InputReg2;
 int Time_IF;
 int Time_ID;
};

I tried printing them out by comparing

while(OutputBuffer.size())
{
    for(int i=0; i<OutputBuffer.size()-1; i++)
       {        if(OutputBuffer[Outputval].Time_IF>OutputBuffer[i+1].Time_IF)
                        Outputval=i+1;}
}

to get the index and then i would print out the respective value

    Outfile<<setw(40)<<OutputBuffer[Outputval].Instline;

erase the printed structure from the vector

OutputBuffer.erase (OutputBuffer.begin()+Outputval);
reset outputval=0

but i find that some of the structures do not get printed..in this method..
is there a better way of sorting a structure vector based on a parameter in the structure...?

Edited by Nick Evan: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by JasonHippy
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.