Original Post
Hey guys I have a quick question about a sorting routine I made. It seems to work fine when the 1st element in the vector list it is sorting is in existence within the string it is sorting( as long as that element comes after all of the other elements in the list) well here I'll post the code and then do some more explaining.
code:
explanation:
tags <- a vector list of tag objects
tag.tagPos <- int val representing the most immediate position of that tag within the string.
private tag getMostImmediate(String s1){
int LastTagPos = -50;
int tagIndex=50;
tag tmpT = new tag();
//Loop through all tags finding most immediate
for(int j=0; j < tags.size(); j++){
tmpT.copy((tag)tags.elementAt(j));
if(LastTagPos == -50){//Set the first tag position and index
LastTagPos = tmpT.tagPos;
tagIndex = j;
}
if(tmpT.tagPos < LastTagPos && tmpT.tagPos > -1){//This tag is more immediate
LastTagPos = tmpT.tagPos;
tagIndex = j;
}
}
return (tag)tags.elementAt(tagIndex);
}
|
- -1 if non-exisitant, otherwise always a positive int.