队列链式存储

#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 Shows(DL *s);//遍历数据 
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");
	}
	
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值