#include "stdafx.h" #include <iostream> using namespace std; typedef int DataType; #define SIZE 100 typedef struct { DataType data[SIZE]; int head,tail; }SqQueue; //初始化 SqQueue init(SqQueue *Q)//顺序型数据结构,初始化之类的方法一定要有返回值 { Q = (SqQueue*)malloc(sizeof(SqQueue)); if(Q==NULL) { printf("%s","init failed"); exit(0); } else { Q->data[0]=0; Q->head = 0; Q->tail = 0; } return *Q; } //判断是否为空 int isQempty(SqQueue *Q) { if(Q->head == Q->tail) return 1; else return 0; } //判断是否满 int isQfull(SqQueue *Q) { if(Q->tail == SIZE) return 1; else return 0; } //进 void inQueue(SqQueue *Q,DataType e) { if(isQfull(Q) ==1) { cout<<"full"<<endl; exit(0); }else { cout<<"q->tail"<<Q->tail<<endl; Q->data[Q->tail++] = e;// cout<<"not full"<<endl; } } //出 void outQueue(SqQueue *Q) { if(isQempty(Q) == 1) { cout<<"out queue empty"<<endl; exit(0); } else { cout<<"out:"<<Q->data[Q->head++]<<endl; } } /*void main() { SqQueue S; S=init(&S); cout<<"isempty"<<isQempty(&S)<<endl; inQueue(&S,1); cout<<"isempty"<<isQempty(&S)<<endl; inQueue(&S,2); cout<<"isempty"<<isQempty(&S)<<endl; outQueue(&S); }*/
时间: 2024-11-19 21:44:07