I have a vector that that stores Node*. A Node has the member properties:row,col,value. In my vector, I have gotten it to where all the Nodes* within the same row but not necessarily in correct column order. So basically I want to sort it so it’s truly in row-major form. Right now, the columns are out of order within each “row”. I appreciate any help you could give!
Edit:
Here is the method I have that is sorting my vector by row. Is there a way to additionally sort the columns as well?
vector<Node*> vect;
int i,j,minIndex;
Node* temp = new Node(NULL,NULL,0,0,0);
for(i=0;i<vect.size()-1;i++)
{
minIndex = i;
for(j=i+1;j<vect.size();j++)
{
if(vect.at(j)->row<vect.at(minIndex)->row)
{
minIndex = j;
}
}
if(minIndex!=i)
{
temp = vect.at(i);
vect.at(i) = vect.at(minIndex);
vect.at(minIndex) = temp;
}
}
You don’t really need to implement your own sorting algorithm here. You can just use the standard template library’s sort() method and then override default the behavior for sorting your Node* vector.
Once you have this less_node structure defined, you would just call: