question

deneshneupane-5739 avatar image
0 Votes"
deneshneupane-5739 asked MinxinYu-MSFT commented

how to sort the array of x,y co-ordinate from the richtextbox in c++/cli with respect to X and Y

i want to sort the richtextbox array with respect to x and y , i dont know how to do? please help



144629-capture.jpg


c++dotnet-cli
capture.jpg (15.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

GuidoFranzke avatar image
0 Votes"
GuidoFranzke answered MinxinYu-MSFT commented

Hello,
this is a simple programming task (sounds like homework).
1. UpdateData the contents of the richeditcontrol to a string variable of the control
2. extract all lines to an integer (x,y)-array (e.g. while-loop, ipos=find(","), v.x=atoi(left(ipos), v.y=atoi(mid(ipos+1), append v to array a)
3. sort array as desired
4. generate string of array (e.g. for-loop, sz+=tostring(a[i].x) + "," + tostring(a[i].y) + "\r\n" )
5. output this string to the richeditcontrol
When you have problems with your code, you can ask (show the code that makes problems) and we will try to help you.
Regards, Guido


· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thankyou very much for your response , i used the following code from example on https://docs.microsoft.com/en-us/dotnet/api/system.array.sort?view=net-5.0 . but the result is shown as mention in the picture i was trying to sort in ascending order.

 ref class myReverserClass : public IComparer
         {
         private:
    
             // Calls CaseInsensitiveComparer::Compare with the parameters reversed.
             virtual int Compare(Object^ x, Object^ y) = IComparer::Compare
             { /*double begin, end;*/
                return ((gcnew CaseInsensitiveComparer)->Compare(y, x));
             }
         };
         void PrintKeysAndValues(cli::array<String^>^ x1, cli::array<String^>^ x2)
         {
             for (int i = 0; i < x1->Length; i++)
             {
                 Console::WriteLine(" {0, -1}, {1}", x1[i], x2[i]);
             }
             Console::WriteLine();
         }


cli::array<String^>^ x1 = gcnew cli::array<String^>(richTextBox1->Lines>Length);
x1 = richTextBox1->Lines;
cli::array<String^>^ x2= gcnew cli::array<String^>(richTextBox2->Lines->Length);
x2 = richTextBox2->Lines;
IComparer^ myComparer = gcnew myReverserClass;
Array::Sort(x1, x2);
PrintKeysAndValues(x1, x2);





144921-capture.jpg


0 Votes 0 ·
capture.jpg (14.0 KiB)

Try to use Array.Reverse.


0 Votes 0 ·

Thankyou for your response , actually problem is the last two number 1460 and 1040 has 4 digits and above one is 3 digits, if I input all the data with same bit then it will work .
if i use Array.Reverse then still there data will not arrange in order.. please help ??
144915-capture.jpg


0 Votes 0 ·
capture.jpg (11.4 KiB)
Show more comments