Write an Arrays.sort sorts objects of classes that implement

Write an Arrays.sort sorts objects of classes that implement Comparable interface ?
ساعد بالإجابة
"إن في قضاء حوائج الناس لذة لا يَعرفها إلا من جربها، فافعل الخير مهما استصغرته فإنك لا تدري أي حسنة تدخلك الجنة."
الإجابات (6)

أين المشكلة؟

مافهمت شنو المطلوب و ماعرفت اسوي الكود

تكتبين له arry ترتب الobj داخلها بعد الاستدعاء
هذا اللي فهمته واتمنى انه صحيح

Arrays.sort() method to sort objects of classes thatimplement Comparable interface: import java.util.*; public class Employeeimplements Comparable<Employee

function defaultCompare(x, y) {
if (x < y)
return -1;
else if (x > y)
return 1;
else
return 0;
}
function swapIndices(array, index1, index2) {
var temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
}
function insertionSort(array, compare) {
compare = compare ? compare : defaultCompare;
for (let i = 0; i < array.length; i++) {
for (let currIndex = i; currIndex > 0; currIndex--) {
if (compare(array[currIndex], array[currIndex - 1]) < 0) {
swapIndices(array, currIndex, currIndex - 1);
}
else {
break;
}
}
}
return array;
}
لو عندي هذا الكود كيف اطبق عليه المطلوب في السؤال ؟
Write an Arrays.sort sorts objects of classes that implement Comparable interface ?

ممكن مساعدة في الحل
لايوجد لديك حساب في عالم البرمجة؟
تحب تنضم لعالم البرمجة؟ وتنشئ عالمك الخاص، تنشر المقالات، الدورات، تشارك المبرمجين وتساعد الآخرين، اشترك الآن بخطوات يسيرة !