Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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....

share|improve this question
2  
    
Which array do you want to sort? There seem to be more than one array in your code. –  user1990169 Mar 8 at 11:25
    
Its the Array TempSet –  user1798057 Mar 8 at 11:27
    
Check out how to use the C++'s standard sort algorithm. –  vonbrand Mar 8 at 15:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.