有谁知道更好更快的排序算法?我的代码:
var n;
var i;
for (n=0; n < mixedSMSPremiumSendedReceivedList.count; n++)
for (i=n+1; i < mixedSMSPremiumSendedReceivedList.count; i++)
{
if (new Date(mixedSMSPremiumSendedReceivedList.get(n).smsData)> new Date(mixedSMSPremiumSendedReceivedList.get(i).smsData))
{
mixedSMSPremiumSendedReceivedList.move(i, n, 1);
n=0;
}
}
我必须按日期排序(yyyy-mm-dd hh:mm:ss)
答案 0 :(得分:0)
答案 1 :(得分:0)
我刚写了几个像这样的案例:
MouseArea{
id:block2mousearea
anchors.fill:block2
drag.target:block2
drag.axis: Drag.XAndYAxis
drag.minimumX:166
drag.maximumX: 622
drag.minimumY:180
drag.maximumY: 371
onClicked: {
var dateRE = /^(\d{2})[\/\- ](\d{2})[\/\- ](\d{4})/;
//dd/mm/yy format Ascending order
function dmyOrdA(a, b){
a = a.replace(dateRE,"$3$2$1");
b = b.replace(dateRE,"$3$2$1");
if (a>b) return 1;
if (a <b) return -1;
return 0;
}
//dd/mm/yy format descending
function dmyOrdD(a, b){
a = a.replace(dateRE,"$3$2$1");
b = b.replace(dateRE,"$3$2$1");
if (a>b) return -1;
if (a <b) return 1;
return 0;
}
//mm/dd/yy format Ascending order
function mdyOrdA(a, b){
a = a.replace(dateRE,"$3$1$2");
b = b.replace(dateRE,"$3$1$2");
if (a>b) return 1;
if (a <b) return -1;
return 0;
}
//mm/dd/yy format descending
function mdyOrdD(a, b){
a = a.replace(dateRE,"$3$1$2");
b = b.replace(dateRE,"$3$1$2");
if (a>b) return -1;
if (a <b) return 1;
return 0;
}
var dateArray = new Array('15/10/2000','28/05/1999','17/09/2005','06/12/2004','02/01/1998');
dateArray.sort(dmyOrdA);
console.log(dateArray);
}
}