I want to sort an array of objects(structs) by its variable "end" This is my struct:
struct tempDomain
{ int start;
int end;
bool empty;
};
This is my Array:
void setMem1DimArr (tempDomain * & Arr1Dim, int & size1, int & size2)
{ tempDomain tempObj;
Arr1Dim= new tempDomain [size1*size2];
for (int i = 0; i< size1*size2; i++)
{ Arr1Dim[i]=tempObj;
Arr1Dim[i].start=0;
Arr1Dim[i].end=0;
Arr1Dim[i].empty=true;
}
return;
}
This is my function where I fill my array:
void SetofDomains::createSets(SetofDomains & DObj)
{
tempDomain tempObj;
for ( int i = 0; i< DObj.repeats; i++)
{
for ( int j= 0; j< DObj.n; j++)
{
if(DObj.arrResults[i][j] != 0)
{
tempObj.start =j-DObj.arrIndices[i][j];
tempObj.end = j;
tempObj.empty=false;
DObj.tempSet[i*j]=tempObj;
}
}
}
return;
}
And Now what i want is a function that sorts the array by the value of variable"end".
The thing is that I know that the values might look like this:
1 2 3 4
1 2 3 4
1 2 3 4
So I know that if you imagine the array as an twodimensiona Array [i][j] or [repeats][n]
that each row is already sorted by increasing value
and I also know that in each row there can only be one value ONCE.
But it can also occur that one value doesn't occur
for example
1 2 4 1 2 3 4 1 3 4
So I need a smart idea how to use the knowledge to save time and space....