示例#1
0
void *pthr_deal_cmd()
{
    while(p_n_over)
    {
        DEBUG_printf("next command!\n");
        if(1==SW)
        {
            DEBUG_printf("Web  Switch is OFF!\n");
            exit(1);
        }
        if(DeQueue(&Q_cmd,&deal_package_cmd))
        {
            DEBUG_printf("get a command head:%s!\n",deal_package_cmd.pkg_head);
            DEBUG_printf("get a command:%s!\n",deal_package_cmd.pkg_cmd);

            QueueTraverse(Q_cmd,visit);
            if(!deal_cmd(deal_package_cmd))
                continue;
            DEBUG_printf("after deal_cmd()\n");
            DEBUG_printf("get a command nonce:%s!\n",deal_package_cmd.pkg_nonce);

            NO_data=0;//data recived
            Insert(&deal_package_cmd,L_cmd,L_cmd);

            printf("new node:%s,%s==========\n",deal_package_cmd.pkg_cmd,deal_package_cmd.pkg_nonce);
            clear_recv(deal_package_cmd);
        }
        else
        {
            DEBUG_printf("queue empty1\n");
            sleep(1);
        }
    }
}
示例#2
0
int main()
{
	int i;
	QElemType d;
	LinkQueue q;
	i=InitQueue(&q);
	if(i)
		printf("成功地构造了一个空队列!\n");
	printf("是否空队列?%d(1:空 0:否)  ",QueueEmpty(q));
	printf("队列的长度为%d\n",QueueLength(q));
	EnQueue(&q,-5);
	EnQueue(&q,5);
	EnQueue(&q,10);
	printf("插入3个元素(-5,5,10)后,队列的长度为%d\n",QueueLength(q));
	printf("是否空队列?%d(1:空 0:否)  ",QueueEmpty(q));
	printf("队列的元素依次为:");
	QueueTraverse(q);
	i=GetHead(q,&d);
	if(i==OK)
	 printf("队头元素是:%d\n",d);
	DeQueue(&q,&d);
	printf("删除了队头元素%d\n",d);
	i=GetHead(q,&d);
	if(i==OK)
		printf("新的队头元素是:%d\n",d);
	ClearQueue(&q);
	printf("清空队列后,q.front=%u q.rear=%u q.front->next=%u\n",q.front,q.rear,q.front->next);
	DestroyQueue(&q);
	printf("销毁队列后,q.front=%u q.rear=%u\n",q.front, q.rear);
	
	return 0;
}
int main()
{
	int a;
	SqQueue S;
	QElemType x, e;
	if (InitQueue(S))    // 判断顺序表是否创建成功,请填空
	{
		printf("A Queue Has Created.\n");
	}
	while (1)
	{
		printf("1:Enter \n2:Delete \n3:Get the Front \n4:Return the Length of the Queue\n5:Load the Queue\n0:Exit\nPlease choose:\n");
		scanf("%d", &a);
		switch (a)
		{
		case 1: scanf("%d", &x);
			if (!EnQueue(S,x)) printf("Enter Error!\n"); // 判断入队是否合法,请填空
			else printf("The Element %d is Successfully Entered!\n", x);
			break;
		case 2: if (!DeQueue(S,e)) printf("Delete Error!\n"); // 判断出队是否合法,请填空
				else printf("The Element %d is Successfully Deleted!\n", e);
				break;
		case 3: if (!GetHead(S,e))printf("Get Head Error!\n"); // 判断Get Head是否合法,请填空
				else printf("The Head of the Queue is %d!\n", e);
				break;
		case 4: printf("The Length of the Queue is %d!\n", QueueLength(S));  //请填空
			break;
		case 5: QueueTraverse(S);//请填空
			break;
		case 0: return 1;
		}
	}
}
示例#4
0
文件: queue.c 项目: upccup/cuplearn
int main()
{
  Status j;
  int i=0, l;
  QElemType d;
  SqQueue Q;

  InitQueue(&Q);
  printf("初始化队列后 队列是否为空%d  1:空 0:非空 \n", QueueEmpty(Q));

  printf("请输入整型队列元素(不超过%d个), -1为提前结束标识符 \n", MAXSIZE-1);

  do
  {
    scanf("%d", &d);
    if (d == -1)
      break;
    EnQueue(&Q, d);
    i++;
  }while(i < MAXSIZE-1);

  printf("队列长度为: %d \n", QueueLength(Q));

  printf("队列是否为空%d  1:空 0:非空 \n", QueueEmpty(Q));
  printf("连续%d次从队首删除元素, 从队尾插入元素: \n", MAXSIZE);

  for(l = 1; l <= MAXSIZE; l++)
  {
    DeQueue(&Q, &d);
    printf("删除的元素是: %d 插入的元素是 %d \n", d, l+100);

    d = l + 100;
    EnQueue(&Q, d);
  }

  printf("现在队列中的元素为: \n");
  QueueTraverse(Q);

  printf("共向队尾插入了 %d 个元素 \n", i+MAXSIZE);
  l = QueueLength(Q);
  if (l-2 > 0)
    printf("现在由队头开始删除 %d 个元素\n", l-2);

  while(QueueLength(Q) > 2)
  {
    DeQueue(&Q, &d);
    printf("删除的元素为 %d \n", d);
  }

  j = GetHead(Q, &d);
  if (j)
    printf("现在队首的元素为 %d \n", d);

  ClearQueue(&Q);
  printf("清空队列后队列是否为空%d  1:空 0:非空 \n", QueueEmpty(Q));
  return 0;
}
示例#5
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);
 }
int main()
{
	Status j;
	int i=0,l;
	QElemType d;
	SqQueue Q;
	InitQueue(&Q);
	printf("初始化队列后,队列空否?%u(1:空 0:否)\n",QueueEmpty(Q));

	printf("请输入整型队列元素(不超过%d个),-1为提前结束符: ",MAXSIZE-1);
	do
	{
		/* scanf("%d",&d); */
		d=i+100;
		if(d==-1)
			break;
		i++;
		EnQueue(&Q,d);
	}while(i<MAXSIZE-1);

	printf("队列长度为: %d\n",QueueLength(Q));
	printf("现在队列空否?%u(1:空 0:否)\n",QueueEmpty(Q));
	printf("连续%d次由队头删除元素,队尾插入元素:\n",MAXSIZE);
	for(l=1;l<=MAXSIZE;l++)
	{
		DeQueue(&Q,&d);
		printf("删除的元素是%d,插入的元素:%d \n",d,l+1000);
		/* scanf("%d",&d); */
		d=l+1000;
		EnQueue(&Q,d);
	}
	l=QueueLength(Q);

	printf("现在队列中的元素为: \n");
	QueueTraverse(Q);
	printf("共向队尾插入了%d个元素\n",i+MAXSIZE);
	if(l-2>0)
		printf("现在由队头删除%d个元素:\n",l-2);
	while(QueueLength(Q)>2)
	{
		DeQueue(&Q,&d);
		printf("删除的元素值为%d\n",d);
	}

	j=GetHead(Q,&d);
	if(j)
		printf("现在队头元素为: %d\n",d);
	ClearQueue(&Q);
	printf("清空队列后, 队列空否?%u(1:空 0:否)\n",QueueEmpty(Q));
	return 0;
}
示例#7
0
int do_lru_clock(Queue* queue,char* input_seq, int frames){
    Queue* queue_p = queue;
    for(int i=0; i<SEQ_SIZE; i++){
        if(*input_seq != ' '){
            int ref_num = atoi(input_seq);
            if(ref_num >= 0){
                int exist = QueueTraverse(queue_p,ref_num, judge_if_exists);
                if(exist == 0){ // not exists
                    if(FRAMES-- <= 0){ // queue already full
                        int k=0;
                        int status = 1;
                        int pos = 0;
                        while(status){
                            if(pos > queue->size){
                                pos = 0;
                            }
                            status = Pop_or_HP_decrease(queue, &k, pos);
                            pos ++;
                        }
                        //Pop(queue,&k);
                        Push(queue,ref_num);
                        PAGE_REPLACEMENT ++;
                    }
                    else{ // not full
                        Push(queue,ref_num);
                    }
                }
                else if(exist > 0){ // exists
                    
                    int k=0;
                    int size = queue->size;
                    while(size!= 0){
                        Pop(queue,&k);
                        if(k != ref_num)
                            Push(queue,k);
                        else if( k == ref_num){
                            Push(queue,ref_num);
                            queue->rear->HP = 1;
                        }
                        size--;
                    }
                }
            }
        }
        input_seq++;
    }
    return 0;
}
示例#8
0
void main()
{
	Status j;
	int i=0,m;
	QElemType d;
	SqQueue Q;
	InitQueue(Q);
	printf("初始化队列后,队列空否?%u(1:空 0:否)\n",QueueEmpty(Q));
	printf("请输入整型队列元素(不超过%d个),-1为提前结束符:",MAX_QSIZE-1);
	do
	{ scanf("%d",&d);
	  if(d==-1)
		  break;
	  i++;
	  EnQueue(Q,d); } while(i<MAX_QSIZE-1);
	printf("队列长度为%d,",QueueLength(Q));
	printf("现在队列空否?%u(1:空 0:否)\n",QueueEmpty(Q));
	printf("连续%d次由队头删除元素,队尾插入元素:\n",MAX_QSIZE);
	for(m=1; m<=MAX_QSIZE; m++)
	{ DeQueue(Q,d);
	  printf("删除的元素是%d,请输入待插入的元素:",d);
	  scanf("%d",&d);
	  EnQueue(Q,d); }
	m=QueueLength(Q);
	printf("现在队列中的元素为");
	QueueTraverse(Q,print);
	printf("共向队尾插入了%d个元素。",i+MAX_QSIZE);
	if(m-2>0)
		printf("现在由队头删除%d个元素,",m-2);
	while(QueueLength(Q)>2)
	{ DeQueue(Q,d);
	  printf("删除的元素值为%d,",d); }
	j=GetHead(Q,d);
	if(j)
		printf("现在队头元素为%d\n",d);
	ClearQueue(Q);
	printf("清空队列后,队列空否?%u(1:空 0:否)\n",QueueEmpty(Q));
	DestroyQueue(Q);
}
示例#9
0
void *pthr_deal_response()
{
    while(p_n_over)
    {
        if(0!=NUL_Queue(&Q_respond))
        {
            wait_res=0;
            if(DeQueue(&Q_respond,&deal_package_resp))
            {
                QueueTraverse(Q_respond,visit);
                rev_respond();
                printf("response node:%s,%s----------\n",deal_package_resp.pkg_cmd,deal_package_resp.pkg_nonce);
                Position curnode = Find(&deal_package_resp,L_cmd);
                if(curnode == NULL)
                {
                    printf("no cmd for responding!\n");
                    exit(1);
                }
                if(strcmp(curnode->item->pkg_cmd,"01") == 0)
                {
                    #ifdef BB_BLACK
                    write_by_type(s4_conf_dir,deal_package_resp.pkg_cmd);
                    #endif // BB_BLACK
                    #ifdef OPENWRT
                    write_s3_auth(deal_package_resp.pkg_cmd);
                    #endif // OPENWRT
                }
                printf("Delete node:%s,%s----------\n",deal_package_resp.pkg_cmd,deal_package_resp.pkg_nonce);
                Delete(&deal_package_resp,L_cmd);
                clear_recv(deal_package_resp);
            }
            else
            {
                DEBUG_printf("respond queue  empty\n");
            }
            NO_data=0;//data recived
        }
    }
}
示例#10
0
int main()
{
    Queue *pq = InitQueue();
    //int i,item;
    int item;

    /*
    printf("0-9 is added into the queue and output as below:\n");

    for(i = 0; i < 10; i++)
    {
        EnQueue(pq, i);
        GetRear(pq, &item);
        printf("%d ", item);
    }
    */

    //
    int ilCount = 0;
    int ilcursor = 36;

    char *pclTmpStart = NULL;
    char pclTmp[16] = "\0";

    char *pclString_1 = "ACK_sps_20140508073602..............00000000027017........................................................ETX_";

    char *pclString_2 = "ACK_sps_20140508073602..............00000000027015........................................................ETX_ACK_sps_20140508073602..............00000000027016........................................................ETX_";

    char *pclString_3 = "ACK_sps_20140508073602..............00000000027011........................................................ETX_ACK_sps_20140508073602..............00000000027012........................................................ETX_ACK_sps_20140508073602..............00000000027013........................................................ETX_ACK_sps_20140508073602..............00000000027014........................................................ETX_";

    printf("length_1: %d\n\n",strlen(pclString_1));
    printf("length_2: %d\n\n",strlen(pclString_2));
    printf("length_3: %d\n\n",strlen(pclString_3));

    //pclTmpStart = strstr(pclString_2,"ACK_");
    //pclTmpStart = strstr(pclString_3,"ACK_");
    //

    EnQueue(pq,27011);
    EnQueue(pq,27012);
    EnQueue(pq,27013);
    EnQueue(pq,27014);

    printf("\nTraverse all element in queue:\n");
    QueueTraverse(pq,print);

    int m = GetSize(pq);
    printf("\nSize: %d\n", m);

    pclTmpStart = strstr(pclString_3,"ACK_");
    for (ilCount = 0; ilCount < (strlen(pclString_3) / LEN); ilCount++)
    {
            memset(pclTmp,0,sizeof(pclTmp));
            if (ilCount == 0)
            {
                    strncpy(pclTmp, pclTmpStart + ilcursor, 14);
            }
            else
            {
                    ilcursor += LEN;
                    if (ilcursor <= strlen(pclString_3))
						strncpy(pclTmp, pclTmpStart + ilcursor, 14);
            }

            TrimZero(pclTmp);
            //printf("%s\n\n",pclString_3+ilcursor);

            //printf("<%d> ilcursor <%d> \tMsgID is <%s>\n", ilCount, ilcursor, pclTmp);

            if (strlen(pclTmp) > 0 && atoi(pclTmp) != 0)
            {
                DeQueue(pq,&item);
                printf("The item in the queue is <%d>\n",item);

                if( atoi(pclTmp) == item)
                {
                    printf("The received msgid<%d> == the one from queue<%d>\n", item, atoi(pclTmp));
                }
                else
                {
                    printf("The received msgid<%d> != the one from queue<%d>\n", item, atoi(pclTmp));
                }
            }
    }

    /*
    printf("\nDequeue all element and print them out one by one:\n");
    for(i = 0; i< m; i++)
    {
        DeQueue(pq,&item);
        printf("%d ",item);
    }
    */

    ClearQueue(pq);
    if(IsEmpty(pq))
        printf("\nMake the queue empty\n");
    DestroyQueue(pq);
    printf("Destruct the queue\n");

    return 0;
}