You are invited to Log in or Register a free Frihost Account!

# Machine Problem No.2 [Pt. 2]

/* -------------------- */
/* 2 - ADJACENCY MATRIX */
/* -------------------- */
char matrix[courseSize][courseSize];
int row = 0, col = 0, i2;

course *headPtr = NULL, *headPtr2 = NULL;

for(i2 = 0; i2 < courseSize; i2++) {
matrix[i2][i2] = 0;
}

for(row = 0; headPtr != NULL; row++) {
col = row + 1;

for(; headPtr2 != NULL; col++) {

/* Traverse linked list for conflicts */

}
}

for(row = 0; row < courseSize; row++) {
for(col = 0; col < courseSize; col++) {
printf("%d ", matrix[row][col]);
}
printf("\n");
}
printf("\n");

/* ------------- */
/* 3- SCHEDULING */
/* ------------- */
int schedule[courseSize], limit = 0, schedColor = 1;
int tempNum2 = 0, defaultColor = 0, row2 = 0;
char finalSched[courseSize][4];

row = 0, i2 = 0;

/* Set everything to uncolored */
int ind = 0;
for(ind = 0; ind < courseSize; ind++) {
schedule[ind] = 0;
}

/* Schedule */
while(1){
while(schedule[defaultColor]!=0){
defaultColor++;
if(defaultColor == courseSize) {
break;
}
}
if(defaultColor == courseSize) {
break;
}

sched *schedNode = (sched *) malloc(sizeof(sched));
schedNode->color = defaultColor;
schedule[defaultColor] = schedColor;

int i = 0, tempNum = 1;
for(i = 0; i < courseSize; i++){
if(tempNum == roomNum) {
break;
}
if(schedule[i] != 0) {
continue;
}

int mark = 1;
sched *travPtr = schedNode;
while(travPtr != NULL){
if(matrix[travPtr->color][i] == 1) {
mark = 0;
}
travPtr = travPtr->next;
}
if(mark){
schedule[i] = schedColor;
tempNum++;
travPtr = schedNode;

while(travPtr->next != NULL) {
travPtr = travPtr->next;
}
sched *temp = (sched *) malloc(sizeof(sched));
temp->color = i;
travPtr->next = temp;
}
}
schedColor++;
}

for(row2 = 0; row2 < courseSize; row2++) {
strcpy(finalSched[row2], hover->courseName);
hover = hover->next;
}

for(tempNum2 = 1; tempNum2 < schedColor; tempNum2++){
printf("TS%d: ", tempNum2);
for(row2 = 0; row2 < courseSize; row2++) {
if(schedule[row2] == tempNum2) {
printf("%s ", finalSched[row2]);
}
}
printf("\n");
}

return 0; /* Program ended successfully */
}
[/code]

I'll include files soon.

0 blog comments below

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP