Hey community members,
I'm just from an unsatisfactory search through Google. I'm trying at a program that automatically reads in numerical values dumped into a file by an Algebra software. Problem is, whenever I try to sort out numbers they are not appearing the way I want them to. These numbers are stored in an array of type array<String^>^. The reason for storing the as character arrays is because they are sometimes too large to be contained in the usual number types i.e. int, double etc, eg. <11797283819727347375364610680> (Not the largest BTW! I'm doing this for someone so I can't explain what they are used for!)
I tried to take advantage of the functionalities inherent in array but it is doing its doing it differently. A sample run gave me <"2","20","3","8">, instead of <"2","3","8","20">. Here's what worked a bit, but still isn't satisfactory to me.
void srt(array<String^>^ &l)
{
bool sorted=false; int j=0, stop=(l->Length)*(l->Length)*(l->Length);
while((sorted==false)&&(j<l->Length)){
for (int i=0;i<(l->Length-1);i++){
String ^tmp; string str1, str2;
MarshalString(l[i],str1); MarshalString(l[i+1],str2);
unsigned long dblval1, dblval2; char *stops="\0";
dblval1=strtoul(str1.c_str(),&stops,8); dblval2=strtoul(str2.c_str(),&stops,8);
if(dblval1 >dblval2){
tmp=l[i]; l[i]=l[i+1]; l[i+1]=tmp;
sorted=false;
}
else sorted=true;
}
j++;
}
}
A sample run is giving me values such as <"0", "7", "12", "13", "4", "6"> which of course are not sorted! Please help