#ifndef STATUS_H
#define STATUS_H
#define FALSE -1
#define TRUE 1
#define OK 1
#define ERROR 0
typedef int ElemType;
typedef int Status;
#endif
#ifndef STACK_H
#define STACK_H
#include <stdio.h>
#include "status.h"
typedef struct Node{
struct Node*next;
int date;
struct Node* rear;
struct Node* front;
}DL,*List;
Status InitNode(DL *s);
Status PushNode(DL *s,ElemType e);
Status PopNode(DL *s,ElemType *e);
Status IsEmptyNode(DL *s);
#endif
#include <stdio.h>
#include "stack.h"
#include "status.h"
Status InitNode(DL *s){
s->rear=s->front=(List)malloc(sizeof(DL));
if(s->rear!=s->front){
return ERROR;
}else{
s->front==NULL;
return OK;
}
}
Status PushNode(DL *s,ElemType e){
DL *p;
p=(List)malloc(sizeof(DL));
p->date=e;
p->next=NULL;
s->front->next=p;
s->front=p;
return OK;
}
Status PopNode(DL *s,ElemType *e){
DL *p;
if(s->front==s->rear)
return ERROR;
e=s->front->date;
return OK;
}
Status IsEmptyNode(DL *s){
if(s->rear==s->front)
return TRUE;
else
return FALSE;
}
#include <stdio.h>
#include "stack.h"
int main(){
DL dl;
DL *s=&dl;
int t,m,n,q,i=1,value;
t=InitNode(s);
if(t==ERROR){
printf("链式队列为不空\n");
}else
printf("链式队列为空\n");
printf("请输入插入的节点个数:");
scanf("%d",&n);
while(i<=n){
printf("你插入的%d个数为:",i);
scanf("%d",&value);
PushNode(s,&value);
i++;
}
t=PushNode(s,&value);;
if(t==OK){
printf("入队成功\n");
}else
printf("入队失败\n");
q=PopNode(s,&value);
if(q==OK)
printf("链式队列队头为:%d",value);
printf("\n");
m=IsEmptyNode(s);
if(m==TRUE){
printf("链式队列为空\n");
}else{
printf("链式队列不为空\n");
}
}