Example #1
0
VOID hwRemove(MINIPORT_ADAPTER *Adapter)
{
	PBUFFER_DESCRIPTOR  dsc;
    ENTER;

	//sangam :Free the pending data packets and control packets
	while(!QueueEmpty(Adapter->hw.Q_Send.Head)) {	//sangam dbg : used only for data packet so free skb
		DumpDebug(DISPATCH, "<1> Freeing Q_Send");
		dsc = (PBUFFER_DESCRIPTOR) QueueGetHead(Adapter->hw.Q_Send.Head);
		if (!dsc) {
			DumpDebug(DISPATCH, "<1> Fail...node is null");
			continue;
		}
		QueueRemoveHead(Adapter->hw.Q_Send.Head);
		if(dsc->Buffer)
			kfree(dsc->Buffer);
		if(dsc)
			kfree(dsc);
	}
	// stop data out buffer
//	if (Adapter->hw.ReceiveBuffer!= NULL) 
//			kfree(Adapter->hw.ReceiveBuffer);
	// stop TempData out buffer
#if 0	//cky 20100624
	if (Adapter->hw.ReceiveTempBuffer!= NULL) 
			kfree(Adapter->hw.ReceiveTempBuffer);
#endif

	hwGPIODeInit();	
	LEAVE;
}
Example #2
0
void BFSTraverse(ALGraph G,void(*Visit)(char*))
{/*按广度优先非递归遍历图G。使用辅助队列Q和访问标志数组visited。*/
  int v,u,w;
  VertexType u1,w1;
  LinkQueue Q;
  for(v=0;v<G.vexnum;++v)
    visited[v]=FALSE; /* 置初值 */
  InitQueue(&Q); /* 置空的辅助队列Q */
  for(v=0;v<G.vexnum;v++) /* 如果是连通图,只v=0就遍历全图 */
    if(!visited[v]) /* v尚未访问 */
    {
      visited[v]=TRUE;
      Visit(G.vertices[v].data);
      EnQueue(&Q,v); /* v入队列 */
      while(!QueueEmpty(Q)) /* 队列不空 */
      {
        DeQueue(&Q,&u); /* 队头元素出队并置为u */
        strcpy(u1,*GetVex(G,u));
        for(w=FirstAdjVex(G,u1);w>=0;w=NextAdjVex(G,u1,strcpy(w1,*GetVex(G,w))))
          if(!visited[w]) /* w为u的尚未访问的邻接顶点 */
          {
            visited[w]=TRUE;
            Visit(G.vertices[w].data);
            EnQueue(&Q,w); /* w入队 */
          }
      }
    }
  printf("\n");
}
Example #3
0
/**
 * 算法7.6,按广度优先非递归遍历图G,使用辅助队列Q和访问标志数组visited
 */
void BFSTraverse(ALGraph G, Boolean visited[], Status (*Visit)(ALGraph G, int v))
{
	int u, v, w;
	LinkQueue Q;
	InitQueue(Q);
	
	for (v = 0; v < G.vexnum; v++) {
		visited[v] = false;
	}

	for (v = 0; v < G.vexnum; v++) {
		if (!visited[v]) {
			visited[v] = true;
			Visit(G, v);
			EnQueue(Q, v);
			while (!QueueEmpty(Q)) {
				DeQueue(Q, u);		//附着元素出列并置为u
				for (w = FirstAdjVex(G, u); w >= 0; w = NextAdjVex(G, u, w)) {
					if (!visited[w]) {
						visited[w] = true;
						Visit(G, w);
						EnQueue(Q, w);
					}
				}
			}
		}
	}
}
Example #4
0
 TElemType Parent(CSTree T,TElemType cur_e)
 { /* 初始条件: 树T存在,cur_e是T中某个结点 */
   /* 操作结果: 若cur_e是T的非根结点,则返回它的双亲,否则函数值为"空" */
   CSTree p,t;
   LinkQueue q;
   InitQueue(&q);
   if(T) /* 树非空 */
   {
     if(Value(T)==cur_e) /* 根结点值为cur_e */
       return Nil;
     EnQueue(&q,T); /* 根结点入队 */
     while(!QueueEmpty(q))
     {
       DeQueue(&q,&p);
       if(p->firstchild) /* p有长子 */
       {
         if(p->firstchild->data==cur_e) /* 长子为cur_e */
           return Value(p); /* 返回双亲 */
         t=p; /* 双亲指针赋给t */
         p=p->firstchild; /* p指向长子 */
         EnQueue(&q,p); /* 入队长子 */
         while(p->nextsibling) /* 有下一个兄弟 */
         {
           p=p->nextsibling; /* p指向下一个兄弟 */
	   if(Value(p)==cur_e) /* 下一个兄弟为cur_e */
	     return Value(t); /* 返回双亲 */
	   EnQueue(&q,p); /* 入队下一个兄弟 */
	 }
       }
     }
   }
   return Nil; /* 树空或没找到cur_e */
 }
DWORD QueueGet (QUEUE_OBJECT *q, PVOID msg, DWORD msize, DWORD MaxWait)
{
    DWORD TotalWaitTime = 0;
    BOOL TimedOut = FALSE;

    WaitForSingleObject (q->qGuard, INFINITE);
    if (q->msgArray == NULL) return 1;  /* Queue has been destroyed */

    while (QueueEmpty (q) && !TimedOut)
    {
        ReleaseMutex (q->qGuard);
        WaitForSingleObject (q->qNe, CV_TIMEOUT);
        if (MaxWait != INFINITE)
        {
            TotalWaitTime += CV_TIMEOUT;
            TimedOut = (TotalWaitTime > MaxWait);
        }
        WaitForSingleObject (q->qGuard, INFINITE);
    }
    /* remove the message from the queue */
    if (!TimedOut) QueueRemove (q, msg, msize);
    /* Signal that the queue is not full as we've removed a message */
    PulseEvent (q->qNf);
    ReleaseMutex (q->qGuard);

    return TimedOut ? WAIT_TIMEOUT : 0;
}
void BFSTraverse(MGraph G)
{
    int i,j;
    Queue Q;
    for(i=0; i<G.numVertexes; i++)
        visited[i]=FALSE;
    InitQueue(&Q);
    for(i=0; i<G.numVertexes; ++i)
    {
        if(!visited[i])
        {
            visited[i]=TRUE;
            printf("%c ",G.vexs[i]);
            EnQueue(&Q,i);
            while(!QueueEmpty(Q))
            {
                DeQueue(&Q,&i);
                for(j=0; j<G.numVertexes; j++)
                {
                    if(G.arc[i][j]==1 && !visited[j])
                    {
                        visited[j]=TRUE;
                        printf("%c ",G.vexs[j]);
                        EnQueue(&Q,j);
                    }
                }
            }
        }
    }
}
Example #7
0
void BFSTraverse(AMLGraph G,Status(*Visit)(VertexType))
{ /* 初始条件: 图G存在,Visit是顶点的应用函数。*/
  /* 操作结果: 从第1个顶点起,按广度优先非递归遍历图G,并对每个顶点调用函数 */
  /*           Visit一次且仅一次。一旦Visit()失败,则操作失败。 */
  /*           使用辅助队列Q和访问标志数组visite */
  int v,u,w;
  VertexType w1,u1;
  LinkQueue Q;
  for(v=0;v<G.vexnum;v++)
    visite[v]=FALSE; /* 置初值 */
  InitQueue(&Q); /* 置空的辅助队列Q */
  for(v=0;v<G.vexnum;v++)
    if(!visite[v]) /* v尚未访问 */
    {
      visite[v]=TRUE; /* 设置访问标志为TRUE(已访问) */
      Visit(G.adjmulist[v].data);
      EnQueue(&Q,v); /* v入队列 */
      while(!QueueEmpty(Q)) /* 队列不空 */
      {
        DeQueue(&Q,&u); /* 队头元素出队并置为u */
        strcpy(u1,*GetVex(G,u));
        for(w=FirstAdjVex(G,u1);w>=0;w=NextAdjVex(G,u1,strcpy(w1,*GetVex(G,w))))
          if(!visite[w]) /* w为u的尚未访问的邻接顶点的序号 */
          {
            visite[w]=TRUE;
            Visit(G.adjmulist[w].data);
            EnQueue(&Q,w);
          }
      }
    }
  printf("\n");
}
/* 邻接矩阵的广度遍历算法 */
void BFSTraverse(MGraph G)
{
	int i, j;
	Queue Q;
	for(i = 0; i < G.numVertexes; i++)
       	visited[i] = FALSE;
    InitQueue(&Q);		/* 初始化一辅助用的队列 */
    for(i = 0; i < G.numVertexes; i++)  /* 对每一个顶点做循环 */
    {
		if (!visited[i])	/* 若是未访问过就处理 */
		{
			visited[i]=TRUE;		/* 设置当前顶点访问过 */
			printf("%c ", G.vexs[i]);/* 打印顶点,也可以其它操作 */
			EnQueue(&Q,i);		/* 将此顶点入队列 */
			while(!QueueEmpty(Q))	/* 若当前队列不为空 */
			{
				DeQueue(&Q,&i);	/* 将队对元素出队列,赋值给i */
				for(j=0;j<G.numVertexes;j++) 
				{ 
					/* 判断其它顶点若与当前顶点存在边且未访问过  */
					if(G.arc[i][j] == 1 && !visited[j]) 
					{ 
 						visited[j]=TRUE;			/* 将找到的此顶点标记为已访问 */
						printf("%c ", G.vexs[j]);	/* 打印顶点 */
						EnQueue(&Q,j);				/* 将找到的此顶点入队列  */
					} 
				} 
			}
		}
	}
}
Example #9
0
 TElemType Parent(BiTree T,TElemType e)
 { // 初始条件: 二叉树T存在,e是T中某个结点
   // 操作结果: 若e是T的非根结点,则返回它的双亲,否则返回"空"
   LinkQueue q;
   QElemType a;
   if(T) // 非空树
   {
     InitQueue(q); // 初始化队列
     EnQueue(q,T); // 树根入队
     while(!QueueEmpty(q)) // 队不空
     {
       DeQueue(q,a); // 出队,队列元素赋给a
       if(a->lchild&&a->lchild->data==e||a->rchild&&a->rchild->data==e) // 找到e(是其左或右孩子)
         return a->data; // 返回e的双亲的值
       else // 没找到e,则入队其左右孩子指针(如果非空)
       {
         if(a->lchild)
           EnQueue(q,a->lchild);
         if(a->rchild)
           EnQueue(q,a->rchild);
       }
     }
   }
   return Nil; // 树空或没找到e
 }
TElemType Parent(CSTree T, TElemType cur_e)
{
	CSTree p, t;
	LinkQueue q;

	InitQueue(q);
	if (T) {
		if (Value(T) == cur_e)
			return Nil;
		EnQueue(q, T);
		while (!QueueEmpty(q)) {
			DeQueue(q, p);
			if (p->firstchild) {
				if (p->firstchild->data == cur_e)
					return Value(p);
				t = p;
				p = p->firstchild;
				EnQueue(q, p);
				while (p->nextsibling) {
					p = p->nextsibling;
					if (Value(p) == cur_e)
						return Value(t);
					EnQueue(q, p);
				}
			}
		}
	}
	return Nil;
}
void LevelOrderTraverse(CSTree T, void (*Visit)(TElemType))
{
	CSTree p;
	LinkQueue q;

	InitQueue(q);
	if (T) {
		Visit(Value(T));
		EnQueue(q, T);
		while (!QueueEmpty(q)) {
			DeQueue(q, p);
			if (p->firstchild) {
				p = p->firstchild;
				Visit(Value(p));
				EnQueue(q, p);
				while (p->nextsibling) {
					p = p->nextsibling;
					Visit(Value(p));
					EnQueue(q, p);
				}
			}
		}
	}
	printf("\n");
}
Example #12
0
 void LevelOrderTraverse(CSTree T,void(*Visit)(TElemType))
 { /* 层序遍历孩子-兄弟二叉链表结构的树T */
   CSTree p;
   LinkQueue q;
   InitQueue(&q);
   if(T)
   {
     Visit(Value(T)); /* 先访问根结点 */
     EnQueue(&q,T); /* 入队根结点的指针 */
     while(!QueueEmpty(q)) /* 队不空 */
     {
       DeQueue(&q,&p); /* 出队一个结点的指针 */
       if(p->firstchild) /* 有长子 */
       {
         p=p->firstchild;
         Visit(Value(p)); /* 访问长子结点 */
         EnQueue(&q,p); /* 入队长子结点的指针 */
         while(p->nextsibling) /* 有下一个兄弟 */
         {
           p=p->nextsibling;
           Visit(Value(p)); /* 访问下一个兄弟 */
           EnQueue(&q,p); /* 入队兄弟结点的指针 */
         }
       }
     }
   }
 }
Example #13
0
Status BFSTraverse(MGraph G,Status(*Visit)(int v))
{
    Queue q;
    QElemType e;
    int i,j;

    for(i=0; i<G.vexnum; i++)
        Visited[i]=FALSE;

    if(!InitQueue(q))return ERROR;
    EnQueue(q,G.vexs[0]);//将第一个顶点入队
    Visited[0]=TRUE;

    printf("广度优先遍历:");
    while(!QueueEmpty(q))
    {
        GetHead(q,e);
        i=LocateVex(G,e);
        for(j=0; j<G.vexnum; j++)
            if(G.arcs[i][j].adj!=0)
                if(!Visited[j])
                {
                    Visited[j]=TRUE;
                    EnQueue(q,G.vexs[j]);
                }
        DeQueue(q,e);
        Visit(e);
    }
    printf("\n");
    return OK;
}
Example #14
0
DMP_INLINE(void) can_RoundRobin(CAN_Bus *can)
{
	CANFrame temp;
		
	if (QueueEmpty(can->xmit))
		return;
	
	io_DisableINT();
	if (!(io_In32(can->ioHandle, can->REQ) & (0x01L << (can->round*2))))
	{
		PopBufQueue(can->xmit, (void*)&temp);
		
		io_Out32(can->ioHandle, can->TX[can->round].TYPE , (unsigned long)temp.type | ((unsigned long)temp.length << 4));
		io_Out32(can->ioHandle, can->TX[can->round].IDR  , temp.identifier);
		io_Out32(can->ioHandle, can->TX[can->round].DATAL, temp.Data.dword[0]);
		io_Out32(can->ioHandle, can->TX[can->round].DATAH, temp.Data.dword[1]);
		
		io_Out32(can->ioHandle, can->REQ, io_In32(can->ioHandle, can->REQ) | (0x01UL << (can->round*2)));
		
		can->round++;
		if (can->round == 3)
			can->round = 0;
	}
	io_RestoreINT();
}
Status GetHead(const SqQueue &Q, QElemType &e)
{
	if(QueueEmpty(Q)) return ERROR;
	
	e = Q.base[Q.front];
	return OK;
}
void BFSTraverse(GraphAdjList GL)
{
    int i;
    EdgeNode *p;
    Queue Q;
    for(i=0; i<GL->numVertexes; i++)
        visited[i]=FLASE;
    InitQueue(&Q);
    for(i=0; i<GL->numVertexes; i++)
    {
        if(!visited[i])
        {
            visited[i]=TRUE;
            printf("%c ",GL->adjList[i].data);
            EnQueue(&Q,i);
            while(!QueueEmpty(Q))
            {
                DeQueue(&Q,&i);
                p=GL->adjList[i].firstedge; //找到当前顶点边表链表头指针
                while(p)
                {
                    if(!visited[p->adjvex]) //若此顶点未被访问
                    {
                        visited[p->adjvex]=TRUE;
                        printf("%c ",GL->adjList[p->adjvex].data);
                        EnQueue(&Q,p->adjvex);
                    }
                    p=p->next;
                }
            }
        }
    }
}
Example #17
0
void BFSTraverse(MGraph G, Status(*Visit)(VertexType))
{/* 初始条件: 图G存在,Visit是顶点的应用函数。算法7.6 */
   /* 操作结果: 从第1个顶点起,按广度优先非递归遍历图G,并对每个顶点调用函数 */
   /*           Visit一次且仅一次。一旦Visit()失败,则操作失败。 */
   /*           使用辅助队列Q和访问标志数组visited */
	int u, v, w;
	VertexType w1, u1;
	SqQueue Q;
	for (v = 0; v < G.vexnum; v++)
		visited[v] = FALSE; //访问标志数组初始化(未被访问)
	InitQueue(Q);
	for (v = 0; v < G.vexnum; v++) {
		if (!visited[v]) {
			visited[v] = TRUE;
			Visit(G.vexs[v]);
			EnQueue(Q, v);
			while (!QueueEmpty(Q)) {
				DeQueue(Q, u); //队头元素出队并置为u
				strcpy(u1, GetVex(G, u));
				for (w = FirstAdjVex(G, u1); w != -1; w = NextAdjVex(G, u1, strcpy(w1, GetVex(G, w))))
					if (!visited[w]) { // w为u的尚未访问的邻接顶点的序号
						visited[w] = TRUE;
						Visit(G.vexs[w]);
						EnQueue(Q, w);
					}
			}
		}
	}
}
void main()
{
	Person dancer[MAXSIZE];
	int number;
	int i;
	Person p;
	SqQueue Mdancers,Fdancers;
	InitQueue(Mdancers);
	InitQueue(Fdancers);
	printf("请输入跳舞的人数:");
	scanf("%d",&number);
	for(i=0;i<number;i++)
	{   
		p=dancer[i];
		printf("请输入第%d位舞者的姓名:",i+1);
		scanf("%s",p.name  );
		printf("请确认舞者的性别(0.女1.男):");
		scanf("%d",&p.sex );
		if(p.sex==0)
			EnQueue(Fdancers,p);
		else
			EnQueue(Mdancers,p);
	}
	printf("the dancing persons are:\n");
	while (QueueEmpty(Fdancers)&&QueueEmpty(Mdancers))
	{
		DeQueue(Fdancers,p);
		printf("%s\n",p.name);
        DeQueue(Mdancers,p);
		printf("%s\n",p.name);
		printf("\n");
	}
	if(QueueEmpty(Fdancers))
	{
		p=GetHead(Fdancers);
		printf("next danse,the first woman to get the partner is:%s",p.name);
	}
	else if(QueueEmpty(Mdancers))
	{
		p=GetHead(Mdancers);
		printf("next danse,the first man to get the partner is:%s",p.name);
	}
	else
		printf("匹配恰好完成!");


}
Example #19
0
BOOL COMMAPI ComRxWait(HCOMM hc, DWORD dwTimeOut)
{
  if (!hc)
    return FALSE;

  if (dwTimeOut == -1)
  {
    while(!ComIsOnline(hc))
      sleep(0);
  }
  else
  {
    /* comisonline takes about 250 ms to run */
    while (!ComIsOnline(hc) && dwTimeOut)
    {
      sleep(0);
      if (dwTimeOut > 275)
        dwTimeOut -= 275;
      else
        dwTimeOut = 0;
    }
  }    
#if 0 /* not yet */
  /* I think this is sort of like select(), but I'm handling that right
   * against read() to avoid wierd-assed blocking problems.
   */

  DWORD rc;

  /* Set the event mask so that we watch for incoming characters */

  ResetEvent(hc->hevRxWait);
  SetCommMask(hc->h, DEFAULT_COMM_MASK | EV_RXCHAR);

  /* Wait for something to happen */

  if (QueueEmpty(&hc->cqRx))
  {
#ifdef DEBUG_PIPE
    PDPrintf("rx: wait\n");
#endif
    rc=WaitForSingleObject(hc->hevRxWait,
                           dwTimeOut==-1 ? INFINITE : dwTimeOut);
#ifdef DEBUG_PIPE
    PDPrintf("rx: end wait\n");
#endif
  }


  /* Disable received-character events */

  SetCommMask(hc->h, DEFAULT_COMM_MASK);

  return (rc != WAIT_TIMEOUT);
#else /* not yet */
  SetCommMask(hc->h, DEFAULT_COMM_MASK | EV_RXCHAR);
  return TRUE;
#endif
}
/*
* @description:返回队头元素
*/
Status GetHeadQueue(LinkQueue Q,QElemType *elem) {
	if(QueueEmpty(Q))
		return ERROR;

	(*elem) = Q.font->data;

	return OK;
}
//----------------------------------------------------------------------
//
//	ProcessSchedule
//
//	Schedule the next process to run.  If there are no processes to
//	run, exit.  This means that there should be an idle loop process
//	if you want to allow the system to "run" when there's no real
//	work to be done.
//
//	NOTE: the scheduler should only be called from a trap or interrupt
//	handler.  This way, interrupts are disabled.  Also, it must be
//	called consistently, and because it might be called from an interrupt
//	handler (the timer interrupt), it must ALWAYS be called from a trap
//	or interrupt handler.
//
//	Note that this procedure doesn't actually START the next process.
//	It only changes the currentPCB and other variables so the next
//	return from interrupt will restore a different context from that
//	which was saved.
//
//----------------------------------------------------------------------
void
ProcessSchedule ()
{
  PCB		*pcb;
  int		i;

  dbprintf ('p', "Now entering ProcessSchedule (cur=0x%x, %d ready)\n",
	    currentPCB, QueueLength (&runQueue));
  // The OS exits if there's no runnable process.  This is a feature, not a
  // bug.  An easy solution to allowing no runnable "user" processes is to
  // have an "idle" process that's simply an infinite loop.
  if (QueueEmpty (&runQueue)) {
    printf ("No runnable processes - exiting!\n");
    exitsim ();	// NEVER RETURNS
  }

// Move the front of the queue to the end, if it is the running process.

  pcb = (PCB *)((QueueFirst (&runQueue))->object);
  if (pcb == currentPCB)
  {
    QueueRemove (&pcb->l);
    QueueInsertLast (&runQueue, &pcb->l);
  }

  // Now, run the one at the head of the queue.
  pcb = (PCB *)((QueueFirst (&runQueue))->object);
  currentPCB = pcb;
  dbprintf ('p',"About to switch to PCB 0x%x,flags=0x%x @ 0x%x\n",
	    pcb, pcb->flags,
	    pcb->sysStackPtr[PROCESS_STACK_IAR]);

  // Clean up zombie processes here.  This is done at interrupt time
  // because it can't be done while the process might still be running
  while (!QueueEmpty (&zombieQueue)) {
    pcb = (PCB *)(QueueFirst (&zombieQueue)->object);
    dbprintf ('p', "Freeing zombie PCB 0x%x.\n", pcb);
    QueueRemove (&pcb->l);
    ProcessFreeResources (pcb);
  }
  // Set the timer so this process gets at most a fixed quantum of time.
  TimerSet (processQuantum);
  dbprintf ('p', "Leaving ProcessSchedule (cur=0x%x)\n", currentPCB);
}
Example #22
0
static int Dequeue(struct Queue *q, uint8_t *data, uint16_t len)
{
	int i;
	for (i = 0; !QueueEmpty(q) && (i < len); i++)
	{
		data[i] = q->q[q->pRD];
		q->pRD = ((q->pRD + 1) ==  QUEUE_SIZE) ? 0 : q->pRD + 1;
	}
	return i;
}
Example #23
0
int* Queue::Delete(int& retvalue)
// delete the first node in queue and return a pointer to its data
{
    if (front == 0) {QueueEmpty(); return 0;};
    QueueNode *x = front;
    retvalue = front->data; // get data
    front = x->link;      // delete front node
    delete x; // free the node
    return &retvalue;
}
Example #24
0
void *messageHandler(void *param){

	/*循环处理队列*/
	while(1){
		/*开始的时候这边没有等号,结果死活通不过。。*/
			while(socket_fd_ctd.status != -1 && !QueueEmpty(socket_fd_ctd.Q)){				//连接建立并且队列不为空的情况下

				/*处理队列中的信息*/
				unsigned char m_data[1024];
				int len;

				memset(m_data, 0x00, 1024);
				len = get_message_from_lq(socket_fd_ctd.Q, m_data);
				if(len == 0)
					continue;

				int comm_type = m_data[0];
				int comm ;
				switch(comm_type){
					case COMM_TYPE_HEARBEAT:
						socket_fd_ctd.socketfd_status = 0;
						break;
						
					case COMM_TYPE_SERVE:
						comm = m_data[1];
						
						if(comm == COMM_SERV_GPS){
							/*上传GPS 信息*/
							LOG(LOG_DEBUG, "服务端要求上传GPS数据信息");
#if IS_MINI2440
						}else if(comm == COMM_SERV_LOCK){
							/*锁车*/
							lock_car();
							LOG(LOG_DEBUG, "服务端下达锁车指令,锁车...");
						}else if(comm == COMM_SERV_UNLOCK){
							/*解锁*/
							led2_status = 0;
							LOG(LOG_DEBUG, "服务端下达解锁指令,已解锁...");
#endif							
						}else if(comm ==  COMM_SERV_BITMAP){
							/*上传图片*/
							static int count = 1;
							unsigned char file_name[6];
							snprintf((char *)file_name,6,"%d.jpg", count++);
							send_file((char *)file_name, socket_fd_ctd.socketfd);
							LOG(LOG_DEBUG, "服务端要求上传图片");
						}
						break;
					default:
						printf("无法识别的指令\n");
						break;
				}
			}
	}
}
Example #25
0
DWORD QueueRemove (QUEUE_OBJECT *q, PVOID msg, DWORD msize)
{
    char *pm;

    if (QueueEmpty(q)) return 1; /* Error - Q is empty */
    pm = q->msgArray;
    /* Remove oldest ("first") message */
    memcpy (msg, pm + (q->qFirst * msize), msize);
    q->qFirst = ((q->qFirst + 1) % q->qSize);
    return 0; /* no error */
}
Example #26
0
   /* 操作结果: 插入c为T中p结点的第i棵子树 */
   int j,k,l,f=1,n=0; /* 设交换标志f的初值为1,p的孩子数n的初值为0 */
   PTNode t;
   if(!TreeEmpty(*T)) /* T不空 */
   {
     for(j=0;j<(*T).n;j++) /* 在T中找p的序号 */
       if((*T).nodes[j].data==p) /* p的序号为j */
         break;
     l=j+1; /* 如果c是p的第1棵子树,则插在j+1处 */
     if(i>1) /* c不是p的第1棵子树 */
     {
       for(k=j+1;k<(*T).n;k++) /* 从j+1开始找p的前i-1个孩子 */
         if((*T).nodes[k].parent==j) /* 当前结点是p的孩子 */
         {
           n++; /* 孩子数加1 */
           if(n==i-1) /* 找到p的第i-1个孩子,其序号为k1 */
             break;
         }
       l=k+1; /* c插在k+1处 */
     } /* p的序号为j,c插在l处 */
     if(l<(*T).n) /* 插入点l不在最后 */
       for(k=(*T).n-1;k>=l;k--) /* 依次将序号l以后的结点向后移c.n个位置 */
       {
         (*T).nodes[k+c.n]=(*T).nodes[k];
         if((*T).nodes[k].parent>=l)
           (*T).nodes[k+c.n].parent+=c.n;
       }
     for(k=0;k<c.n;k++)
     {
       (*T).nodes[l+k].data=c.nodes[k].data; /* 依次将树c的所有结点插于此处 */
       (*T).nodes[l+k].parent=c.nodes[k].parent+l;
     }
     (*T).nodes[l].parent=j; /* 树c的根结点的双亲为p */
     (*T).n+=c.n; /* 树T的结点数加c.n个 */
     while(f)
     { /* 从插入点之后,将结点仍按层序排列 */
       f=0; /* 交换标志置0 */
       for(j=l;j<(*T).n-1;j++)
         if((*T).nodes[j].parent>(*T).nodes[j+1].parent)
         {/* 如果结点j的双亲排在结点j+1的双亲之后(树没有按层序排列),交换两结点*/
           t=(*T).nodes[j];
           (*T).nodes[j]=(*T).nodes[j+1];
           (*T).nodes[j+1]=t;
           f=1; /* 交换标志置1 */
           for(k=j;k<(*T).n;k++) /* 改变双亲序号 */
             if((*T).nodes[k].parent==j)
               (*T).nodes[k].parent++; /* 双亲序号改为j+1 */
             else if((*T).nodes[k].parent==j+1)
               (*T).nodes[k].parent--; /* 双亲序号改为j */
         }
     }
     return OK;
   }
   else /* 树T不存在 */
     return ERROR;
 }

 Status deleted[MAX_TREE_SIZE+1]; /* 删除标志数组(全局量) */
 void DeleteChild(PTree *T,TElemType p,int i)
 { /* 初始条件: 树T存在,p是T中某个结点,1≤i≤p所指结点的度 */
   /* 操作结果: 删除T中结点p的第i棵子树 */
   int j,k,n=0;
   LinkQueue q;
   QElemType pq,qq;
   for(j=0;j<=(*T).n;j++)
     deleted[j]=0; /* 置初值为0(不删除标记) */
   pq.name='a'; /* 此成员不用 */
   InitQueue(&q); /* 初始化队列 */
   for(j=0;j<(*T).n;j++)
     if((*T).nodes[j].data==p)
       break; /* j为结点p的序号 */
   for(k=j+1;k<(*T).n;k++)
   {
     if((*T).nodes[k].parent==j)
       n++;
     if(n==i)
       break; /* k为p的第i棵子树结点的序号 */
   }
   if(k<(*T).n) /* p的第i棵子树结点存在 */
   {
     n=0;
     pq.num=k;
     deleted[k]=1; /* 置删除标记 */
     n++;
     EnQueue(&q,pq);
     while(!QueueEmpty(q))
     {
       DeQueue(&q,&qq);
       for(j=qq.num+1;j<(*T).n;j++)
         if((*T).nodes[j].parent==qq.num)
         {
           pq.num=j;
           deleted[j]=1; /* 置删除标记 */
           n++;
           EnQueue(&q,pq);
         }
     }
     for(j=0;j<(*T).n;j++)
       if(deleted[j]==1)
       {
         for(k=j+1;k<=(*T).n;k++)
         {
           deleted[k-1]=deleted[k];
           (*T).nodes[k-1]=(*T).nodes[k];
           if((*T).nodes[k].parent>j)
             (*T).nodes[k-1].parent--;
         }
         j--;
       }
     (*T).n-=n; /* n为待删除结点数 */
   }
 }
Example #27
0
/* 取得对头元素 */
bool GetHead(SqQueue Q, DataType* e)
{
	if (QueueEmpty(Q) == false)
	{
		errno = EINVAL;	/* 参数不对 */
		return false;
	}

	*e = Q.data[Q.head];

	return false;
}
Example #28
0
/*********************************************************************
* Delete Queue (Line Mode)
**********************************************************************/
int QueueDeleteL(SqQueue *sq, int *qdata)
{
	   if(QueueEmpty(sq, 0))
	   {
         printf("The queue is empty!\n");
         return -1;
	   }
	   
     sq->qcount --;
     *qdata = sq->queue[sq->qcount];
     
     return 0;
}
Example #29
0
 void main()
 {
   Status j;
   int i,n;
   QElemType d;
   SqQueue Q;
   InitQueue(Q);
   printf("初始化队列后,队列空否?%u(1:空 0:否)\n",QueueEmpty(Q));
   printf("队列长度为:%d\n",QueueLength(Q));
   printf("请输入队列元素个数n: ");
   scanf("%d",&n);
   printf("请输入%d个整型队列元素:\n",n);
   for(i=0;i<n;i++)
   {
     scanf("%d",&d);
     EnQueue(Q,d);
   }
   printf("队列长度为:%d\n",QueueLength(Q));
   printf("现在队列空否?%u(1:空 0:否)\n",QueueEmpty(Q));
   printf("现在队列中的元素为: \n");
   QueueTraverse(Q,visit);
   DeQueue(Q,d);
   printf("删除队头元素%d\n",d);
   printf("队列中的元素为: \n");
   QueueTraverse(Q,visit);
   j=GetHead(Q,d);
   if(j)
     printf("队头元素为: %d\n",d);
   else
     printf("无队头元素(空队列)\n");
   ClearQueue(Q);
   printf("清空队列后, 队列空否?%u(1:空 0:否)\n",QueueEmpty(Q));
   j=GetHead(Q,d);
   if(j)
     printf("队头元素为: %d\n",d);
   else
     printf("无队头元素(空队列)\n");
   DestroyQueue(Q);
 }
Example #30
0
/* 删除对头元素 */
bool DeQueue(SqQueue* Q, DataType* e)
{
	if (QueueEmpty(*Q) == false)
	{
		errno = EINVAL;	/* 参数不对 */
		return false;
	}

	*e = Q->data[Q->head];
	Q->head = (Q->head + 1) % MAXQSIZE;

	return true;
}