Code:
struct Queue{
Queue *next;
Queue *previous;
Queue *head_ptr;
char job_Name[15]; //all char not sure where the problem is at
unsigned int arrival_Time;
unsigned int deadLine;
unsigned int jobLength;
char job_Type[3]; ///this line too
};
void insertAscending(Queue *queue,char jN[10], int aT,int jL, int dL, char joT[3]){
// Reserve space for new node and fill it with data
Queue *temp = new Queue;
Queue *awesome = queue->head_ptr;
temp->head_ptr = queue->head_ptr;
temp->job_Name[10] = *jN; //this line
temp->arrival_Time = aT;
temp->jobLength = jL;
temp->deadLine = dL;
temp->job_Type[3] = *joT; //this line
temp->next = NULL;
printf("%i %t" , jL, " ");
Queue *temp1, *temp2;
if (temp->head_ptr == NULL) { // no item
queue->head_ptr = temp;
} else if (awesome->next == NULL) { // one item
if (awesome->arrival_Time < temp->arrival_Time) {
insertLast(temp);
}else {
insertFirst(temp);
}
} else {
// two or more
temp1 = queue->head_ptr;
temp2 = queue->head_ptr;
while (temp1->arrival_Time < aT && temp1->next != NULL){
temp2 = temp1;
temp1 = temp1->next;
}
if (temp1 == queue->head_ptr && temp2 == queue->head_ptr){
insertFirst(temp); // first node
} else if (temp1->arrival_Time < aT || temp2->arrival_Time < aT ){
insertLast(temp); // last node
} else { // middle node
insert(temp2, temp2->arrival_Time);
}
}
}
Queue *printlist(Queue *s){
Queue *temp = s->head_ptr;
if (temp == NULL) {
printf("\nThe List is empty\n");
} else {
printf("The items in the Queue:\n");
do {
printf("%s %t" , temp->job_Name, " " ); //print job name
printf("%i %t" , temp->arrival_Time , " ");
printf("%i %t" , temp->jobLength , " ");
printf("%i %t" , temp->deadLine , " ");
printf("%s %t" , temp->job_Type , " "); //print job type
printf("\n");
// Move to next node (if present)
temp = temp->next;
} while (temp != NULL);
printf("\n");
}
}
int main(){
Queue *TXT = new Queue;
Queue *MM = new Queue;
Queue *FP = new Queue;
TXT->head_ptr = NULL;
MM->head_ptr = NULL;
FP->head_ptr = NULL;
FILE *fp;
//open file
fp=fopen("input_2011.txt", "r");
char jN[5]; //this line
int aT = 0;
int dL;
int jL;
char jT[3]; //this line
for(int eof = 0; eof < 35; eof++){
//scan text file to get variables
fscanf (fp, "%s %i %i %i %s", &jN, &aT, &jL, &dL, &jT);
//insert into the proper queue
if(strcmp(jT , "TXT") == 0 ){
insertAscending(TXT, jN , aT, jL, dL,jT);
}
else if(strcmp(jT , "MM")== 0){
insertAscending(MM, jN , aT,jL, dL,jT);
}
else {
insertAscending(FP, jN , aT,jL, dL,jT);
}
}
//fclose (fp);
printlist(TXT);
printlist(MM);
printlist(FP);
return 0;
}