Exemple #1
0
Fichier : 03B.c Projet : neotaso/pp
int main(){
  int len;
  char str1[MAX+2],str2[MAX+2];
  char *sp;

  fgets(str1,sizeof(str1),stdin);
  fgets(str2,sizeof(str2),stdin);
  len = strlen(str1);
  if(str1[len-1]=='\n')str1[len-1]='\0';
  len = strlen(str2);
  if(str2[len-1]=='\n')str2[len-1]='\0';
  sp = findhead(str1,str2);

  printf(sp);
  printf("\n");
  return 0;
}
Exemple #2
0
Task * queueup(Task * fel,Server * servers) // keep track of the task that gets in to the server and form one final queue
{
	float currentT = 0;
	int remS = 64;
	Task * newQ =  NULL;
	Task * currentQ0 = createdq(-1);
	Task * currentQ1 = createdq(-1);
	Task * queue = NULL;
	Task * temp = NULL;

	while(fel != NULL)
	{
		currentT = fel->artime;
		if(fel -> type == 0)//this is a dq event
		{
			remS++;
			servers = freeS(servers, currentT);
			while(currentQ0 != NULL)
			{	
				temp = dequeue(currentQ0,remS);
				if (temp != NULL)
				{
					remS -= temp->nofstasks;
					servers = busyS(servers,temp,currentT); //set servers to work
					temp->timelq = currentT;
					queue = recordQ(queue,temp);
					mergedq(temp, fel ,currentT);
					deltask(temp);
				}
				else
				{
					break;
				}
			}
			while(currentQ1 != NULL)
			{	
				temp = dequeue(currentQ1,remS);
				if (temp != NULL)
				{
					remS -= temp->nofstasks;	
					servers = busyS(servers,temp,currentT);
					temp->timelq = currentT;
					queue = recordQ(queue,temp);
					mergedq(temp,fel,currentT);
					deltask(temp);
				}
				else
				{
					break;
				}
			}
		}
		else if (fel->type == 1)//if the head of the fel is a task
		{
			
			if(fel->nofstasks <= remS)
			{
				remS -= fel->nofstasks;
				servers = busyS(servers,fel,currentT);
				fel->timelq = currentT;
				queue = recordQ(queue,fel);
				mergedq(fel,fel,currentT);
			}			
			else
			{
				newQ = copyQ(fel);
				if(fel->priority ==	0)
				{
					currentQ0 = mergeFEL(currentQ0,newQ);//mergeFEL will return the head of currentQ
				}
				else
				{
					currentQ1 = mergeFEL(currentQ1,newQ);
				}
			}
		}
		temp = fel->next;
		deltask(fel);
		fel = temp;
	}
	task_destroy(findhead(currentQ0));
	task_destroy(findhead(currentQ1));
	return queue;
}