Esempio n. 1
0
/*宽度优先*/ 
void BFS ( LGraph Graph, Vertex S)
{   
    Queue Q;     
    Vertex V;
    PtrToAdjVNode W; 
  
    InitializeQueue(&Q);
    /* 访问顶点S:此处可根据具体访问需要改写 */
    printf("% d",S);
    Printed[S] = true; /*本例中表示该节点已被输出*/
    Visited[S] = true; /* 标记S已访问 */
    EnQueue(S,&Q); /* S入队列 */
      
    while ( !QueueIsEmpty(&Q) ) {
        DeQueue(&V,&Q);  /* 弹出V */
        for( W=Graph->G[V].FirstEdge; W; W=W->Next ) /* 对图中的每个顶点W */
            if ( !Visited[W->AdjV] ) {
                /* 访问顶点W */
                printf("% d",W->AdjV);
                Printed[W->AdjV] = true; 
                Visited[W->AdjV] = true; 
                EnQueue(W,&Q); /* W入队列 */
            }
    }
}
Esempio n. 2
0
int BuildSignatureDatabaseSearchMachine(signature_db* SignatureDatabase)
{
  if (!SignatureDatabase)
    return -1;

  if (!SignatureDatabase->Trie && BuildSignatureDatabaseTrie(SignatureDatabase) != 0)
    return -1;

  InitializeSearchMachine(SignatureDatabase->SearchMachine, SignatureDatabase->Trie);

  search_machine* SM = SignatureDatabase->SearchMachine;

  // Phase 2
  queue* Queue = xcalloc(1, sizeof(queue));
  InitializeQueue(Queue);

  for (size_t AlphabetIndex = 0; AlphabetIndex < UNIT_CARDINALITY; ++AlphabetIndex)
  {
    trie* Node = SM->Goto[ROOT_IDENTIFIER][AlphabetIndex];
    //if (Node && Node->Identifier != ROOT_IDENTIFIER)
    if (!Node || Node->Identifier != ROOT_IDENTIFIER)
    {
      SM->Fail[Node->Identifier] = SM->Trie;
      Enqueue(Queue, Node);
    }
  }

  while (Peek(Queue) != NULL)
  {
    trie* R = Dequeue(Queue);

    for (size_t AlphabetIndex = 0; AlphabetIndex < UNIT_CARDINALITY; ++AlphabetIndex)
    {
      trie* S = SM->Goto[R->Identifier][AlphabetIndex];

      // Not 100% about this
      if (S)
      {
        Enqueue(Queue, S);
        trie* ST = SM->Fail[R->Identifier];

        // Not 100% about this
        while (!SM->Goto[ST->Identifier][AlphabetIndex])
        {
          ST = SM->Fail[ST->Identifier];
        }

        SM->Fail[S->Identifier] = SM->Goto[ST->Identifier][AlphabetIndex];

        // out(u) = out(u) UNION out(fail(u))
        SM->Out[S->Identifier] = UniqExtendList(SM->Out[S->Identifier], SM->Out[SM->Fail[S->Identifier]->Identifier]);
      }
    }
  }

  FreeQueue(Queue);
  Queue = NULL;
  return 0;
}
Esempio n. 3
0
/*initalizes all needed objects for opencl
OCLHandle - Datastructure containg the opencl objects
*/
bool SetupOpenCLEnvironment( OpenCLData * OCLHandle)
{
	InitializePlatform(OCLHandle);
	InitializeDevice(OCLHandle);
	InitializeContext(OCLHandle);
	InitializeProgram(OCLHandle);
	InitializeKernels(OCLHandle);
	InitializeQueue(OCLHandle);

	return true;
}
Esempio n. 4
0
//创建节点
static Node * MakeNode(const Item * pi)
{
	Node * new_node;

	new_node = (Node *)malloc(sizeof(Node));//为新节点分配空间
	if(new_node != NULL)//分配成功
	{
		new_node->queue = InitializeQueue();
		EnQueue(*pi,new_node->queue);//将元素的地址赋给新节点的
		new_node->left = new_node->right = NULL;//将新节点的左右节点指针置为空
	}
	return new_node;
}
Esempio n. 5
0
int main (){
  int Cont, TamStr;
  char Risada[51];
  DescFila Descritor;
  scanf("%s",Risada);
  TamStr = strlen(Risada);
  InitializeQueue(&Descritor);
  for(Cont=0;Cont<TamStr;Cont++)
    if(Risada[Cont] == 'a' || Risada[Cont] == 'e' || Risada[Cont] == 'i' || Risada[Cont] == 'o' || Risada[Cont] == 'u')
      Queue(&Descritor,Risada[Cont]);
  for(Cont=TamStr-1;Cont>=0;Cont--)
    if(Descritor.Inicio != NULL && Descritor.Inicio->Vogal == Risada[Cont])
      Enqueue(&Descritor);
  if(Descritor.Qtd == 0) printf("S\n");
  else printf("N\n");
  return 0;
}
Esempio n. 6
0
/*****************************************************************************
** Procedure:  CJTLine::read
**
** Arguments:  'istm' - Input stream
**
** Returns:    pointer to istm
**
** Description:  This function is called to serialize data in from the
**               registry.  The line object has already been completely
**               initialized by the TSP++ library
**
*****************************************************************************/
TStream& CJTLine::read(TStream& istm)
{
    // Adjust the line device capabilities.  We don't support any of the
    // line device capability flags, and don't need dialing parameters since the
    // switch doesn't allow them to be adjusted.
    LPLINEDEVCAPS lpCaps = GetLineDevCaps();
    lpCaps->dwDevCapFlags = 0;
	lpCaps->dwUUICallInfoSize = 1024;
	lpCaps->dwLineStates &= ~(LINEDEVSTATE_RINGING | LINEDEVSTATE_MSGWAITON | LINEDEVSTATE_MSGWAITOFF | 
				LINEDEVSTATE_NUMCOMPLETIONS | LINEDEVSTATE_TERMINALS | LINEDEVSTATE_ROAMMODE | 
				LINEDEVSTATE_BATTERY | LINEDEVSTATE_SIGNAL | LINEDEVSTATE_LOCK | LINEDEVSTATE_COMPLCANCEL |
				LINEDEVSTATE_MAINTENANCE);

	// Adjust our address information
	CTSPIAddressInfo* pAddress = GetAddress(0);
	_TSP_ASSERTE (pAddress != NULL);

	LINEADDRESSCAPS* lpACaps = pAddress->GetAddressCaps();
	lpACaps->dwMaxCallDataSize = MAXCALLDATA_SIZE;
	lpACaps->dwCallerIDFlags = 
	lpACaps->dwConnectedIDFlags = 
	lpACaps->dwRedirectionIDFlags =
	lpACaps->dwRedirectingIDFlags =
	lpACaps->dwCalledIDFlags =
	lpACaps->dwCalledIDFlags & ~LINECALLPARTYID_PARTIAL;
	lpACaps->dwCallStates &= ~(LINECALLSTATE_SPECIALINFO | LINECALLSTATE_RINGBACK);
	lpACaps->dwDialToneModes &= ~LINEDIALTONEMODE_SPECIAL;
	lpACaps->dwDisconnectModes &= ~LINEDISCONNECTMODE_REJECT;

	// Adjust the various line properties based on the type of line this is.
	if (GetLineType() == Station)
		InitializeStation();
	else if (GetLineType() == RoutePoint)
		InitializeRoutePoint();
	else if (GetLineType() == Queue)
		InitializeQueue();
	else if (GetLineType() == PredictiveDialer)
		InitializeDialer();
	else if (GetLineType() == VRU)
		InitializeVRU();

	// We didn't read any extra information from the stream.
	return CTSPILineConnection::read(istm);

}// CJTLine::read
Esempio n. 7
0
void Level_Traverse(node *ptr) {
	InitializeQueue();	
	Put(ptr);

	while (!IsQueueEmpty()) {
		ptr = Get();
		Display(ptr);

		if (ptr->left != head)
			Put(ptr->left);

		if (ptr->mid != head)
			Put(ptr->mid);

		if (ptr->right != head)
			Put(ptr->right);
	}
}
	SyncColoringsOptimalEnumerator::SyncColoringsOptimalEnumerator(int verticesCount, int outDegree)
		: n(verticesCount), k(outDegree),
		  graph(nullptr),
		  syncChecker(verticesCount, outDegree),
		  coloringsGraph(BuildColoringsGraph(verticesCount, outDegree)),
		  Current(0) {

		colorings.reserve(GraphColoring::ColoringsCount(verticesCount, outDegree));
		GraphColoring coloring(n, k);
		do {
			colorings.push_back(coloring);
		}
		while (coloring.NextColoring());

		bfsQueue.Resize(colorings.size());
		bfsDistance.resize(colorings.size());
		InitializeQueue();

	}
Esempio n. 9
0
int main(void)
{
    Queue line;
    Item temp;
    char ch;

    InitializeQueue(&line);
    puts("Testing the Queue interface. Type a to add a value,");
    puts("type d to delete a value, and type q to quit.");
    while ((ch = getchar()) != 'q')
    {
        if (ch != 'a' && ch != 'd')   /* ignore other input */
            continue; 
        if ( ch == 'a')
        {
            printf("Integer to add: ");
            scanf("%d", &temp);
            if (!QueueIsFull(&line))
            {
                printf("Putting %d into queue\n", temp);
                EnQueue(temp,&line);
            }
           else
               puts("Queue is full!");
        }
        else
        {
            if (QueueIsEmpty(&line))
                puts("Nothing to delete!");
            else
            {
                 DeQueue(&temp,&line);
                 printf("Removing %d from queue\n", temp);
            }
        }
        printf("%d items in queue\n", QueueItemCount(&line));
        puts("Type a to add, d to delete, q to quit:");
    }
    EmptyTheQueue(&line);
    puts("Bye!");

    return 0;
}
Esempio n. 10
0
int main(void)
{
    Queue line;
    Item temp;
    char ch;
    
    InitializeQueue(&line);
    puts("testing the queue interface. type a to  a value");
    puts("type d to delete a value, and type q tp quit.");
    while ((ch = getchar()) != 'q')
    {
        while (ch != 'a' && ch != 'd')
            continue;
        if (ch == 'a')
        {
            printf("integer to add: ");
            scanf("%d",&temp);
            if (!QueueIsFull(&line)) //添加前确认一下队列
            {
                printf("putting %d into queue\n", temp); //重复输入的内容,确认一遍
                EnQueue(temp, &line);
            }
        }
        else
        {
            if (QueueIsEmpty(&line))
                puts("nothing to delete!");
            else
            {
                DeQueue(&temp, &line);
                printf("removing %d from queue\n",temp);
            }
        }
        printf("%d item in queue\n",QueueItemCount(&line));
        puts("type a to add, d to delete, q to quit: ");
    }
    EmptyTheQueue(&line);
    puts("bye!");
    
    return 0;
}
GENERICAPI NTSTATUS  InitializeGenericExtension(PGENERIC_EXTENSION pdx, PGENERIC_INIT_STRUCT isp)
    {                            // InitializeGenericExtension
    if(isp->Size < FIELD_OFFSET(GENERIC_INIT_STRUCT, Flags)
        || !isp->DeviceObject
        || !isp->Ldo
        || !isp->Pdo
        || !isp->StartDevice
        || !isp->StopDevice
        || !isp->RemoveDevice
        || isp->DeviceQueue && !isp->StartIo)

        return STATUS_INVALID_PARAMETER;

    RtlZeroMemory(pdx, sizeof(GENERIC_EXTENSION));

    pdx->DeviceObject = isp->DeviceObject;
    pdx->LowerDeviceObject = isp->Ldo;
    pdx->Pdo = isp->Pdo;
    pdx->StartDevice = isp->StartDevice;
    pdx->StopDevice = isp->StopDevice;
    pdx->RemoveDevice = isp->RemoveDevice;

    if(isp->Size >= FIELD_OFFSET(GENERIC_INIT_STRUCT, OkayToRemove) + sizeof(PQUERYFUNCTION))
        {                        // set OkayToStop & OkayToRemove pointers
        pdx->OkayToStop = isp->OkayToStop;
        pdx->OkayToRemove = isp->OkayToRemove;
        }                        // set OkayToStop & OkayToRemove pointers

    if((pdx->RemoveLock = isp->RemoveLock))
        IoInitializeRemoveLock(pdx->RemoveLock, 0, 0, 0);

    pdx->state = STOPPED;
    
    pdx->devpower = PowerDeviceD0;
    pdx->syspower = PowerSystemWorking;
    POWER_STATE state;
    state.DeviceState = PowerDeviceD0;
    PoSetPowerState(pdx->DeviceObject, DevicePowerState, state);

    // In version 1.3, I added support for multiple IRP queues

    if(isp->Size >= FIELD_OFFSET(GENERIC_INIT_STRUCT, NumberOfQueues) + sizeof(ULONG)
        && isp->NumberOfQueues)
        {                        // multiple queues
        ULONG i;
        if(isp->DeviceQueue || isp->StartIo)
            return STATUS_INVALID_PARAMETER;    // can't mix new and old ways of identifying queues
        if(isp->Size < FIELD_OFFSET(GENERIC_INIT_STRUCT, Queues) + isp->NumberOfQueues * 2 * sizeof(PVOID))
            return STATUS_INVALID_PARAMETER;    // init structure not big enough
        for (i = 0; i < isp->NumberOfQueues; ++i)
            if(!isp->Queues[i].DeviceQueue || !isp->Queues[i].StartIo)
                return STATUS_INVALID_PARAMETER;    // none of the entries can be NULL

        pdx->nqueues = isp->NumberOfQueues;
        pdx->queues = (PDEVQUEUE*) ExAllocatePoolWithTag(NonPagedPool, isp->NumberOfQueues * sizeof(PDEVQUEUE), SPOT_TAG);
        if(!pdx->queues)
            return STATUS_INSUFFICIENT_RESOURCES;

        for (i = 0; i < isp->NumberOfQueues; ++i)
            {                    // for each queue
            pdx->queues[i] = isp->Queues[i].DeviceQueue;
            InitializeQueue(pdx->queues[i], isp->Queues[i].StartIo);
            }                    // for each queue
        }                        // multiple queues

    else if(isp->DeviceQueue)
        {                        // single queue
        pdx->nqueues = 1;
        pdx->queues = (PDEVQUEUE*) ExAllocatePoolWithTag(NonPagedPool, sizeof(PDEVQUEUE), SPOT_TAG);
        if(!pdx->queues)
            return STATUS_INSUFFICIENT_RESOURCES;
        pdx->queues[0] = isp->DeviceQueue;
        InitializeQueue(pdx->queues[0], isp->StartIo);
        }                        // single queue

    // In version 1.9, I added support for FlushPendingIo.
    // In version 1.10, GetDevicePowerState

    if(isp->Size >= FIELD_OFFSET(GENERIC_INIT_STRUCT, Queues))
        {                        // additional reserved fields
        pdx->FlushPendingIo = isp->FlushPendingIo;
        pdx->GetDevicePowerState = isp->GetDevicePowerState;
        }                        // additional reserved fields

    // Capture the mini-driver name for messages. This needs to be in ANSI because
    // unicode conversions at or above DISPATCH_LEVEL are not allowed. In retrospect, I
    // should have made the field in the INIT struct be in ANSI to start with...

    if(!isp->DebugName.Length)
        strcpy(pdx->DebugName, "GENERIC");
    else
        {                        // convert debug name
        ANSI_STRING asname = {0, sizeof(pdx->DebugName) - 1, pdx->DebugName};
        RtlUnicodeStringToAnsiString(&asname, &isp->DebugName, FALSE);
        pdx->DebugName[asname.Length] = 0;
        }                        // convert debug name

    if(isp->Size >= FIELD_OFFSET(GENERIC_INIT_STRUCT, Flags) + sizeof(ULONG))
        pdx->Flags = isp->Flags & GENERIC_CLIENT_FLAGS;

    if(isp->Size >= FIELD_OFFSET(GENERIC_INIT_STRUCT, RestoreDeviceContext) + sizeof(PCONTEXTFUNCTION))
        {                        // get power helper functions
        pdx->QueryPower = isp->QueryPower;
        pdx->SaveDeviceContext = isp->SaveDeviceContext;
        pdx->RestoreDeviceContext = isp->RestoreDeviceContext;
        }                        // get power helper functions

    if(isp->Size >= FIELD_OFFSET(GENERIC_INIT_STRUCT, PerfBoundary) + sizeof(DEVICE_POWER_STATE))
        pdx->PerfBoundary = isp->PerfBoundary;
    else
        pdx->PerfBoundary = PowerDeviceUnspecified;

    if(pdx->PerfBoundary == PowerDeviceUnspecified)
        pdx->PerfBoundary = PowerDeviceMaximum; // inhibit POWER_SEQUENCE optimization

    // Initialize variables related to asynchrounous IOCTL management. In version 2.0, this
    // is now always done rather than depending on a flag in the init struct.

    InitializeListHead(&pdx->PendingIoctlList);
    pdx->IoctlAbortStatus = 0;
    KeInitializeSpinLock(&pdx->IoctlListLock);

    // Initialize to manage registered device interfaces

    KeInitializeEvent(&pdx->iflock, SynchronizationEvent, TRUE);
    InitializeListHead(&pdx->iflist);

    // Indicate we handle power IRPs at PASSIVE_LEVEL

    pdx->DeviceObject->Flags |= DO_POWER_PAGABLE;

    KdPrint(("GENERIC - Initializing for %s\n", pdx->DebugName));

    // If device honors paging-path notifications, initialize a synchronization
    // event in the signalled state to act as a simple mutex (SP-7)

    if(pdx->Flags & GENERIC_USAGE_PAGING)
        KeInitializeEvent(&pdx->evPagingPath, SynchronizationEvent, TRUE);

    // If requested to do so, register an AutoLaunch interface

    if(pdx->Flags & GENERIC_AUTOLAUNCH)
        GenericRegisterInterface(pdx, &GUID_AUTOLAUNCH_NOTIFY);

    // Register a power management interface

    GenericRegisterInterface(pdx, &GUID_GENERIC_POWER);

#ifdef _X86_
    win98 = IsWin98();
#endif

    return STATUS_SUCCESS;
    }                            // InitializeGenericExtension
Esempio n. 12
0
GENERICAPI NTSTATUS GENERIC_EXPORT InitializeGenericExtension(PGENERIC_EXTENSION pdx, PGENERIC_INIT_STRUCT isp)
	{							// InitializeGenericExtension
	if (isp->Size < FIELD_OFFSET(GENERIC_INIT_STRUCT, Flags)
		|| !isp->DeviceObject
		|| !isp->Ldo
		|| !isp->Pdo
		|| !isp->StartDevice
		|| !isp->StopDevice
		|| !isp->RemoveDevice
		|| isp->DeviceQueue && !isp->StartIo)

		return STATUS_INVALID_PARAMETER;

	RtlZeroMemory(pdx, sizeof(GENERIC_EXTENSION));

	pdx->DeviceObject = isp->DeviceObject;
	pdx->LowerDeviceObject = isp->Ldo;
	pdx->Pdo = isp->Pdo;
	pdx->StartDevice = isp->StartDevice;
	pdx->StopDevice = isp->StopDevice;
	pdx->RemoveDevice = isp->RemoveDevice;

	if (isp->Size >= FIELD_OFFSET(GENERIC_INIT_STRUCT, OkayToRemove) + sizeof(PQUERYFUNCTION))
		{						// set OkayToStop & OkayToRemove pointers
		pdx->OkayToStop = isp->OkayToStop;
		pdx->OkayToRemove = isp->OkayToRemove;
		}						// set OkayToStop & OkayToRemove pointers

	if ((pdx->dqReadWrite = isp->DeviceQueue))
		{						// queue reads & writes
		if (!isp->StartIo)
			return STATUS_INVALID_PARAMETER;
		InitializeQueue(pdx->dqReadWrite, isp->StartIo);
		}						// queue reads & writes

	if ((pdx->RemoveLock = isp->RemoveLock))
		IoInitializeRemoveLock(pdx->RemoveLock, 0, 0, 0);

	pdx->state = STOPPED;
	
	pdx->devpower = PowerDeviceD0;
	pdx->syspower = PowerSystemWorking;
	POWER_STATE state;
	state.DeviceState = PowerDeviceD0;
	PoSetPowerState(pdx->DeviceObject, DevicePowerState, state);

	// Capture the mini-driver name for messages. This needs to be in ANSI because
	// unicode conversions at or above DISPATCH_LEVEL are not allowed

	if (!isp->DebugName.Length)
		strcpy(pdx->DebugName, "GENERIC");
	else
		{						// convert debug name
		ANSI_STRING asname = {0, sizeof(pdx->DebugName) - 1, pdx->DebugName};
		RtlUnicodeStringToAnsiString(&asname, &isp->DebugName, FALSE);
		pdx->DebugName[asname.Length] = 0;
		}						// convert debug name

	if (isp->Size >= FIELD_OFFSET(GENERIC_INIT_STRUCT, Flags) + sizeof(ULONG))
		pdx->Flags = isp->Flags & GENERIC_CLIENT_FLAGS;

	if (isp->Size >= FIELD_OFFSET(GENERIC_INIT_STRUCT, RestoreDeviceContext) + sizeof(PCONTEXTFUNCTION))
		{						// get power helper functions
		pdx->QueryPower = isp->QueryPower;
		pdx->SaveDeviceContext = isp->SaveDeviceContext;
		pdx->RestoreDeviceContext = isp->RestoreDeviceContext;
		}						// get power helper functions

	if (isp->Size >= FIELD_OFFSET(GENERIC_INIT_STRUCT, PerfBoundary) + sizeof(DEVICE_POWER_STATE))
		pdx->PerfBoundary = isp->PerfBoundary;
	else
		pdx->PerfBoundary = PowerDeviceUnspecified;

	if (pdx->PerfBoundary == PowerDeviceUnspecified)
		pdx->PerfBoundary = PowerDeviceMaximum; // inhibit POWER_SEQUENCE optimization

	// Initialize variables related to asynchrounous IOCTL management.

	if (pdx->Flags & GENERIC_PENDING_IOCTLS)
		{						// driver may cache asyncronous IOCTLs
		InitializeListHead(&pdx->PendingIoctlList);
		pdx->IoctlAbortStatus = 0;

		// We need to initialize our IOCTL spin lock sometime, but just once.
		// Acquiring the cancel spin lock to guard this operation is a bit of
		// a hack, I suppose, but note that a class driver like this one never
		// gets an actual chance to initialize, so it's not my fault...

		KIRQL oldirql;
		IoAcquireCancelSpinLock(&oldirql);	// any global spin lock would do
		if (!IoctlListLockInitialized)
			{					// initialize global lock
			IoctlListLockInitialized = TRUE;
			KeInitializeSpinLock(&IoctlListLock);
			}					// initialize global lock
		IoReleaseCancelSpinLock(oldirql);
		}						// driver may cache asynchronous IOCTLs

	// Initialize to manage registered device interfaces

	ExInitializeFastMutex(&pdx->iflock);
	InitializeListHead(&pdx->iflist);

	// Indicate we handle power IRPs at PASSIVE_LEVEL

	pdx->DeviceObject->Flags |= DO_POWER_PAGABLE;

	KdPrint(("GENERIC - Initializing for %s\n", pdx->DebugName));

	// If requested to do so, register an AutoLaunch interface

	if (pdx->Flags & GENERIC_AUTOLAUNCH)
		GenericRegisterInterface(pdx, &GUID_AUTOLAUNCH_NOTIFY);

	// Register a power management interface

	GenericRegisterInterface(pdx, &GUID_GENERIC_POWER);

#ifdef _X86_
	win98 = IsWin98();
#endif

	return STATUS_SUCCESS;
	}							// InitializeGenericExtension
Esempio n. 13
0
File: mall.c Progetto: ludwig123/ADT
int main(void)
{
    Queue line;
    Item temp;   //关于顾客的数据
    int hours;   //模拟的小时数
    int perhours;  //每小时的平均顾客数
    long cycle, cyclelimit; //循环计数器,计数器的上界
    long turnaways = 0;  //因队列已满而被拒绝的顾客数量
    long customers = 0;  //被加入队列的顾客数
    long served = 0;
    long sum_line = 0;  //累计的队列长度
    long wait_time = 0;  //从当前到Sigmund空闲所需的时间
    double min_per_cust;
    long line_wait = 0;
    
    InitializeQueue(&line);
    srand(time(0));
    puts("case study: sigmund lander's advice booth");
    puts("enter the number of simulation hours: ");
    scanf("%d",&hours);
    cyclelimit = MIN_PER_HR * hours;
    puts("enter the average number of customers per hour: ");
    scanf("%d",&perhours);
    min_per_cust = MIN_PER_HR / perhours;
    
    for (cycle = 0; cycle < cyclelimit; cycle++)
    {
        if (newcustomer(min_per_cust))
        {
         if (QueueIsFull(&line))  //如果队列是满的
            turnaways++;
            else  //如果队列不是满的
            {
                customers++;
                temp = customertime(cycle);
                EnQueue(temp, &line);
            }
        }
        
        if (wait_time <= 0 && !QueueIsEmpty(&line)) //如果不需要等待,且队列不是空的;意味着只有一个人!
        {
            DeQueue(&temp, &line);
            wait_time = temp.processtime;
            line_wait += cycle - temp.arrive;
            served++;
        }
        if (wait_time > 0)
            wait_time--;
        sum_line += QueueItemCount(&line);
    }
    
    if (customers > 0)
    {
        printf("customer acccepted: %ld\n",customers);
        printf("customer served:%ld\n",served);
        printf(   "turnaways: %ld\n",turnaways);
        printf("average queue size: %.2f\n",(double)sum_line / cyclelimit);
        printf(" average wait time: %.2f minutes\n",(double)line_wait / served);
    }
    else
        puts("no customer!");
    EmptyTheQueue(&line);
    puts("BYE!");
    
    return 0;
}
	void SyncColoringsOptimalEnumerator::EnumerateColoringsOf(const Graph& graph) {
		this->graph = &graph;
		Current = 0;
		InitializeQueue();
	}
Esempio n. 15
0
void main(void) 
{
  /* put your own code here */
  
  SET_TCNT_PRESCALE( TCNT_PRESCALE_8);
	TSCR1 = TSCR1_INIT;
  
	seg_init();
	CANinit(THE_FLOOR);
	SET_BITS(LED_DDR, LED1_MASK|LED2_MASK);

	node_id = PORTB & 3; //get hardware specified node id
	
	while (!(CANCTL0&0x10));

	CANRFLG = 0xC3;
	CANRIER = 0x01;

	InitializeQueue(&rec);	// Create the Recieve Queue
	
	
	
     clear_seg();

	EnableInterrupts;

  for(;;) 
  {

	if(IsQueueEmpty(rec) != 0)
	{		
		DeQueue(&rec);
		Parse_Floor();
	}
  
  // button 1 press
    if((PTJ & (SWITCH1_MASK |SWITCH2_MASK) )== SWITCH1_MASK) 
    {
        if(THE_FLOOR == F1 || THE_FLOOR == F2)
        {
            if (last != SWITCH1_MASK) 
            {   // check if button already pressed 

            	data[0] = THE_FLOOR;
            	data[1] = CALL_SWITCH1;
            	data[2] = UP;
            	
            	(void)CANSend(CONTROLLER, 0x00, 0x00, DATA_LENGTH, data); 
            	last =  SWITCH1_MASK;        
            }  
        }
        else if(THE_FLOOR == F3)
        {
            if (last != SWITCH1_MASK) 
            {   // check if button already pressed 

                data[0] = THE_FLOOR;
                data[1] = CALL_SWITCH1;
                data[2] = DOWN;

                (void)CANSend(CONTROLLER, 0x00, 0x00, DATA_LENGTH, data); 
                last =  SWITCH1_MASK;        
            }  
        }

    }                
  
  //button 2 press
    else if((PTJ & (SWITCH1_MASK |SWITCH2_MASK) )== SWITCH2_MASK)
    {
        if(THE_FLOOR == F2)
        {
            if (last != SWITCH2_MASK) 
            { // check if button already pressed    
                data[0] = THE_FLOOR;
                data[1] = CALL_SWITCH2;
                data[2] = DOWN;

                CANSend(CONTROLLER, 0x00, 0x00, DATA_LENGTH, data); 
                last =  SWITCH2_MASK;
            } 
        }
 
    }
  
  else
  last = 0;
  
  
  // Updates the LED
  FORCE_BITS(PTS,0b00001100 , led) ;


  

  } /* loop forever */
  /* please make sure that you never leave main */
}