0
-(void)insertEvent:(stRs232Timer*)pEvent
{
BOOL bFound = NO;
NSLog(@"insertEvent");
pEvent->uExpirationTime = pEvent->uPeriod-45;
// Insert the item into the event queue in chronological order
int no = [m_cPendingEventList count];
stRs232Timer* val;
for(int i=0;i<no;i++)
{
val = (stRs232Timer*)[m_cPendingEventList objectAtIndex:i];
if (pEvent->uExpirationTime < val->uExpirationTime)
{
NSLog(@"Going to insert!!");
if (i=0) {
[m_cPendingEventList insertObject:(void*)pEvent atIndex:i];
bFound = YES;
break;
}
else //Insert before
{
[m_cPendingEventList insertObject:(void*)pEvent atIndex:(i-1)];
bFound = YES;
break;
}
}
i++;
}
if (!bFound) {
[m_cPendingEventList insertObject:(void*)pEvent atIndex:(no+1)];//Insert last
}
}
這是以正確的順序搜索和插入事件的正確方法嗎?插入陣列
我在上面的if()stmts中獲得運行時間休息。
這就是我正在做的insertbefore是正確的I - 1。 – spandana 2011-05-26 10:30:03
我會照你告訴我那樣做。謝謝。 – spandana 2011-05-26 10:30:36
它給我像NSMutable陣列警告不會迴應-insertObject – spandana 2011-05-26 10:34:21