简体   繁体   中英

How can I compare System Strings while creating forms using CLR/CLI (.NET Framework)(C++)?

PROBLEM: I am trying to create a visualization of Priority Queue using WindowsForms (CLR/CLI, C++, .NET Framework). I am done with the enqueue part but when I try to visualize the dequeue function, the values are dequeued in the conventional manner of FIFO. How can I Visualize the dequeue-ing of the values according to their priority?

MY LOGIC: While inserting the values through enqueue function, the priority of every element is stored in the priority array. And while deleting the values in dequeue function, I simply try to compare the values stored in priority array with the values in the priority label through a loop, and if the value is matched, the element is shown to be dequeued on the form. According to my analysis, the strings of Labels and those stored in the Priority Queue are not being compared correctly, if that is the issue, kindly suggest the correct method.

Otherwise, kindly guide if there is a mistake in my logic, or if there is any other issue. The code of Delete (Dequeue) function is given below:

array<String^>^ priority = gcnew array<String^>(6);

void Delete(){
            if (front == -1 || front > rear)
            {
                MessageBox::Show("Queue UnderFlow");
                return;
            }
            else
            {
                count++;

                for (int i = 0; i < 6; i++)
                {
                    if (priority[i] == label1->Text)
                    {
                        label1->Text = String::Empty;
                        label12->Text = String::Empty;
                        return;
                    }
                    if (priority[i] == label2->Text)
                    {
                        label2->Text = String::Empty;
                        label11->Text = String::Empty;
                        return;
                    }
                    if (priority[i] == label3->Text)
                    {
                        label3->Text = String::Empty;
                        label10->Text = String::Empty;
                        return;
                    }
                    if (priority[i] == label4->Text)
                    {
                        label4->Text = String::Empty;
                        label7->Text = String::Empty;
                        return;
                    }
                    if (priority[i] == label5->Text)
                    {
                        label5->Text = String::Empty;
                        label8->Text = String::Empty;
                        return;
                    }
                    if (priority[i] == label6->Text)
                    {
                        label6->Text = String::Empty;
                        label9->Text = String::Empty;
                        return;
                    }
                }

return will exit the function early, try to delete return .

A little suggestion:

You should use front and rear more, your upload code is more like an array than a queue. Queues can prevent traversing the entire array under certain circumstances. I suggest changing the code to:

             for (front = 0; front != rear; front++)
             {
                 if (priority[front] == label1->Text)
                 {
                     label1->Text = String::Empty;
                     label12->Text = String::Empty;
                 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM