Esempio n. 1
0
// creates new event, inserts into correct place in the array
// resizes array if necessary using resize fxn
void Day::scheduleEvent(int startTime, int endTime, string description){
    if (eventCount == eventCapacity) {
	resizeList();
    }
    Event newEvent;
    newEvent.setStartTime(startTime);
    newEvent.setEndTime(endTime);
    newEvent.setDescription(description);
    if (eventCount == 0) { 
		eventList[eventCount] = newEvent;
	        eventCount++;
		return;
    }
    //loop through and find where event should go
    for (int i = 0; i < eventCount; i++) {
	if (newEvent.getStartTime() < eventList[i].getStartTime()) {
	    //shift following events over
	    for (int j = eventCount; j > i; j--){
		eventList[j] = eventList[j-1];
	    }
	    eventList[i] = newEvent;	
	    eventCount++;
	    return;
	}
    }
}
Esempio n. 2
0
File: list.c Progetto: deewar/pg
inline void addToList_u( List *list , int value , int unique) {


    if ( list->count >= list->size) resizeList(list, list->size *2);


    if ( unique ) {
        int i ;
        for ( i = 0 ; i< list->count; i++) {
            if ( list->items[i] == value)
                return;
        }
    }


    list->items[list->count] = value;
    list->count ++;
}