zoukankan      html  css  js  c++  java
  • 队列

    #include<iostream>
     #include<string.h>
     #include<ctype.h>
     #include<malloc.h>
     #include<limits.h>
     #include<stdio.h>
     #include<stdlib.h>
     //#include<io.h>
     #include<math.h>
     //#include<process.h>
     #define TRUE 1
     #define FALSE 0
     #define OK 1
     #define ERROR 0
     #define INFEASIBLE -1
    using namespace std;
    typedef int QElemType;
    typedef int Status;
    typedef struct QNode
    {
        QElemType data;
        QNode *next;
    }*QueuePtr;
    struct LinkQueue
    {
       QueuePtr front,rear;
    };
    void InitQueue(LinkQueue &Q)
    {
        if(!(Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode))))
        exit(OVERFLOW);
        Q.front->next=NULL;
    }
    void EnQueue(LinkQueue &Q,QElemType e)
    {
        QueuePtr p;
        if(!(p=(QueuePtr)malloc(sizeof(QNode))))
        exit(OVERFLOW);
        p->data=e;
        p->next=NULL;
        Q.rear->next=p;
        Q.rear=p;
    }
    Status DeQueue(LinkQueue &Q,QElemType &e)
    {
        QueuePtr p;
        if(Q.front==Q.rear)
          return ERROR;
          p=Q.front->next;
          e=p->data;
          Q.front->next=p->next;
          if(Q.rear==p)
            Q.rear=Q.front;
            free(p);
            return OK;
    }
    int main()
    {
        int i;
        QElemType d;
        LinkQueue q;
        InitQueue(q);
        while(scanf("%d",&i)!=EOF)
        {
            EnQueue(q,i);
        }
        while(q.front!=q.rear)
        {DeQueue(q,d);
        printf("%d",d);}
    
    }
  • 相关阅读:
    文件操作回顾
    数据类型回顾
    面向对象三大特性之封装与多态
    面向对象之继承
    轮播图
    jQuery事件操作
    jQuery动画效果
    jQuery篇
    文档对象模型
    javascript
  • 原文地址:https://www.cnblogs.com/13224ACMer/p/4975921.html
Copyright © 2011-2022 走看看