Here I have a structure of calls
typedef struct calls
{
string contact;
string startTime;
string endTime;
} callDetails;
vector <callDetails> details;
In my code i'm reading a file in to this vector.In that file there some details about calls(contact,call start time and end time)I've shown couple of line of that file below
Contact,Start Time,End Time
711256677,7,7.15
711345678,13,13.07
772345627,20,20.55
Here what i want to do is sort and display this call details on my program.I wrote a code to get the call duration(end time-start time) and sort it.But I cant display those sorted details properly.I want to display it in ascending order.also in this manner contact number , start time ,end time
.Basically the same above shown table like structure but sorted according to the call duration.Below I've shown the code i wrote.
calls callDetails[maxNames];
float callDuration[maxNames] , startMin[maxNames], endMin[maxNames] , temp;
readAllCalls(callDetails);
for (int i = 0 ; i < details.size() ; i++){
startMin[i] = stof(details[i].startTime);
endMin[i] = stof(details[i].endTime);
callDuration[i] = (endMin[i] - startMin[i]) - 0.4;
}
for (int j = 0; j < (details.size() - 1); j++){
for (int i = j + 1; i < details.size(); i++){
if (callDuration[j] < callDuration[i]){
temp = callDuration[j];
callDuration[j] = callDuration[i];
callDuration[i] = temp;
}
}
}
can someone help me with this?(Display the call details in the same table but sorted)