zoukankan      html  css  js  c++  java
  • 循环队列的链式存储结构

     1 #include "stdafx.h"
     2 #include <iostream>
     3 #include <exception>
     4 using namespace std;
     5 
     6 //循环队列的顺序存储结构
     7 
     8 typedef int Status;
     9 const int ok = 1;
    10 const int error = 0;
    11 const int maxSize = 5;
    12 
    13 typedef int QElemType;
    14 
    15 typedef struct QNode
    16 {
    17     QElemType data;
    18     struct QNode *next;
    19 }QNode,*QueuePtr;
    20 
    21 typedef struct 
    22 {
    23     QueuePtr front,rear;
    24 }LinkQueue;
    25 
    26 Status EnQueue(LinkQueue *Q,const QElemType e)
    27 {
    28     QueuePtr p = (QueuePtr)malloc(sizeof(QNode));
    29     if(!p)
    30         exit(OVERFLOW);
    31     p->data=e;
    32     p->next = NULL;
    33     Q->rear->next=p;
    34     Q->rear=p;
    35     return ok;
    36 }
    37 Status DeQueue(LinkQueue *Q)
    38 {
    39     if(Q->front==Q->rear)
    40         return error;
    41     QueuePtr p;
    42     p=Q->front->next;
    43     cout<<p->data<<endl;
    44     Q->front->next = p -> next;
    45     if(Q->rear == p)
    46         Q->rear = Q->front;
    47     free(p);
    48     return ok;
    49 }
    50 int _tmain(int argc, _TCHAR* argv[])
    51 {
    52 
    53     return 0 ;
    54 }
  • 相关阅读:
    MYSQL: 什么是MYSQLD Service
    100 logging模块
    099 hashlib和hmac模块
    098 json和pickle模块
    097 sys模块
    096 os模块
    095 random模块
    094 datetime模块
    093 time模块
    092 模块基础实战之ATM和购物车系统分文件处理
  • 原文地址:https://www.cnblogs.com/crazycodehzp/p/3541811.html
Copyright © 2011-2022 走看看