Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int schedule_lecture(classroomT classrooms_array[], courseT* course, const int duration){
- int i, j, k, l, availability_flag,m;
- for (i = 0; i < MAX_ROOMS; i++) {
- if (course != NULL && course -> enrolled_count <= classrooms_array[i].capacity) {
- for (j = 0; j < WORKING_HOURS; j++) {
- /* Lecture shouldn't last over working hours */
- if (j + duration > WORKING_HOURS) {
- break;
- }
- for (k = 0; k < WORKING_DAYS; k++) {
- availability_flag = 1;
- for (l = j; l < j+duration; l++) {
- if (classrooms_array[i].schedule[l][k] != NULL) {
- availability_flag = 0;
- break;
- }
- }
- if(availability_flag){
- /* Checking if the professor has a lecture in another classroom */
- for(m=0; m<MAX_ROOMS; m++){
- for (l = j; l < j+duration; l++) {
- if (classrooms_array[m].schedule[l][k] != NULL && !strcmp(classrooms_array[m].schedule[l][k]->prof_name,course->prof_name)) {
- availability_flag = 0;
- break;
- }
- }
- }
- }
- /* If an available slot is found, set all pointers of that time slot towards the course */
- if (availability_flag) {
- for (l = j; l < j+duration; l++) {
- classrooms_array[i].schedule[l][k] = course;
- }
- return i;
- }
- }
- }
- }
- }
- return -1;
- }
RAW Paste Data