using namespace std;#define OK 1#define ERROR 0#define OVERFLOW -2typedef int ELEMTYPE;typedef int Status;typedef struct LNo..._c++结构体入队">
赞
踩
#include "stdafx.h" #include <iostream> using namespace std; #define OK 1 #define ERROR 0 #define OVERFLOW -2 typedef int ELEMTYPE; typedef int Status; typedef struct LNode //结点结构 单链表 { ELEMTYPE data; struct LNode *next; }LNode,*Queueptr; typedef struct //队列的结构 { Queueptr front; //队头指针 Queueptr rear; //队尾指针 }LinkQueue; Status initLinkQueue(LinkQueue &Q) { Q.front = Q.rear = new LNode; //带头结点 初始化都指向头结点 if(!Q.front) return OVERFLOW; Q.front->next = NULL; } bool isEmpty(LinkQueue &Q) //判队空 { if (Q.front->next == NULL) return true; else return false; } void EnQueue(LinkQueue &Q,ELEMTYPE e) //入队 { LNode *p = (LNode *)malloc(sizeof(LNode)); p->data = e; p->next = NULL; Q.rear->next = p; Q.rear = p; } void ExQueue(LinkQueue &Q,ELEMTYPE &e) //出队 { if(isEmpty(Q)) return; LNode *p = Q.front->next; e = p->data; Q.front->next = Q.front->next->next; delete (p); if (isEmpty(Q)) //若空表 尾指针置初位 Q.rear = Q.front; } void Visit(LinkQueue &Q) { LNode *p = Q.front->next; while(p) { cout << p->data << " "; p = p->next; } cout << endl; }
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。