تبدیل کد مرتب سازی بر اساس چند خصوصیت جاوا به سی شارپ

بپرسید
  • رضا H رضا H
  • 59 ماه قبل
  • 59 ماه قبل
  • 302 نمایش

0

{{ digitTrunc(content.likes) }}

سلام. کد مرتب سازی زیر ، در جاوا وجود دارد :


            if (activateTransactionMerging)
            {
                Collections.sort(dataset.getTransactions(), new Comparator(){
                @Override
                /**
				 * Compare two transactions
				 */
                public int compare(Transaction t1, Transaction t2)
                {
                    // we will compare the two transaction items by items starting
                    // from the last items.
                    int pos1 = t1.items.length - 1;
                    int pos2 = t2.items.length - 1;

                    // if the first transaction is smaller than the second one
                    if (t1.items.length < t2.items.length)
                    {
                        // while the current position in the first transaction is >0
                        while (pos1 >= 0)
                        {
                            int subtraction = t2.items[pos2] - t1.items[pos1];
                            if (subtraction != 0)
                            {
                                return subtraction;
                            }
                            pos1--;
                            pos2--;
                        }
                        // if they ware the same, they we compare based on length
                        return -1;

                        // else if the second transaction is smaller than the first one
                    }
                    else if (t1.items.length > t2.items.length)
                    {
                        // while the current position in the second transaction is >0
                        while (pos2 >= 0)
                        {
                            int subtraction = t2.items[pos2] - t1.items[pos1];
                            if (subtraction != 0)
                            {
                                return subtraction;
                            }
                            pos1--;
                            pos2--;
                        }
                        // if they are the same, they we compare based on length
                        return 1;

                    }
                    else
                    {
                        // else if both transactions have the same size
                        while (pos2 >= 0)
                        {
                            int subtraction = t2.items[pos2] - t1.items[pos1];
                            if (subtraction != 0)
                            {
                                return subtraction;
                            }
                            pos1--;
                            pos2--;
                        }
                        // if they ware the same, they we compare based on length
                        return 0;
                    }
                }

            });
            }


تا جایی که میدونم بر اساس تابع compare ، تراکنش ها رو مرتب می کنه. روش زیر در کد بالا هست. 

چه روشی برای پیاده سازی این تیکه کد زیر در سی شارپ هست ؟



Collections: IComparable
Collections.sort(dataset.getTransactions(), new Comparator(){ 
    Override 
    /** 
    * Compare two transactions 
    */ 
    public int compare(Transaction t1, Transaction t2) {
        /**
        * Codes 
        */ 
    } 
});
دوره های شبکه، برنامه نویسی، مجازی سازی، امنیت، نفوذ و ... با برترین های ایران

پاسخ ها به این سوال

پاسخ ها به این سوال

{{ digitTrunc(post.likes) }}

این پست در تاریخ {{ dateString(new Date(post.deleteDate)) }} توسط {{ post.deletedByUser }} حذف شده است.

دلیل حذف: {{ post.deleteReason ?? 'نامشخص' }}

{{ err }}
{{ post.userAchivements.rhodiumAchievements }}
{{ post.userAchivements.platinumAchievements }}
{{ post.userAchivements.goldAchievements }}
{{ post.userAchivements.silverAchievements }}
{{ post.userAchivements.bronzeAchievements }}
{{ timeSince(new Date(post.date)) }} قبل

برای ثبت پاسخ خود در وب سایت وارد حساب کاربری خود شوید
قابلیت ارسال مطلب توسط مدیریت سایت غیر فعال شده است