star

搜索

RSS

RSS Link

计数器

140254
栈的头文件
栈与队列的三个例子

队列的头文件

Star posted @ 2010年10月05日 04:02 in C语言 with tags 数据结构 循环队列 链式队列 , 2737 阅读
/* 数据结构 队列的实现 Queue.h
 * author : star
 */
 
//防止重复定义
#ifndef QUEUE_H
#define QUEUE_H

#include "defs.h"

//初始化大小为n的队列
int InitSqqueue(SQQUEUE *Q, int n)
{
	Q->data = (ElemType *)malloc((n+1) * sizeof(ElemType));
	if(Q->data == NULL)
		return 0;
	Q->front = Q->rear = 0;
	Q->size  = n + 1;
	return 1;
}

//销毁队列
void DestroySqqueue(SQQUEUE *Q)
{
	free(Q->data);
	Q->data = NULL;
	Q->front = Q->rear = Q->size = 0;
}

//判断队空还是满
int IsSqqueueEmpty(SQQUEUE Q)
{
	return Q.front == Q.rear;
}

int IsSqqueueFull(SQQUEUE Q)
{
	return Q.front == (Q.rear+1) % Q.size;
}

//入队
int EnSqqueue(SQQUEUE *Q, ElemType e)
{
	if(IsSqqueueFull(*Q))
		return 0;
	Q->data[Q->rear] = e;
	Q->rear = (Q->rear+1) % Q->size;\
	return 1;
}

//出队
int DeSqqueue(SQQUEUE *Q, ElemType *e)
{
	if(IsSqqueueFull(*Q))
		return 0;
	*e = Q->data[Q->front];
	Q->front = (Q->front+1) % Q->size;
	return 1;
}

//队列长度
int SqqueueLen(SQQUEUE Q)
{
	return (Q.size + Q.rear + Q.front) % Q.size;
}

//初始化空链式队
void InitLkqueue(LKQUEUE *Q)
{
	Q->front = Q->rear = NULL;
}

//销毁链式队列
void DestroyLkqueue(LKQUEUE *Q)
{
	LQNODEPTR p;
	while(Q->front != NULL)
	{
		p = Q->front;
		Q->front = p->next;
		free(p);
	}
	Q->rear = NULL;
}

//入链队
int EnLkqueue(LKQUEUE *Q, ElemType e)
{
	LQNODEPTR p;
	p = (LQNODEPTR)malloc(sizeof(LQNODE));
	if(p == NULL)
		return 0;
	p->data = e;
	p->next = NULL;
	if(Q->front == NULL)
		Q->front      = Q->rear = p;
	else
		Q->rear->next = Q->rear = p;
	return 1;
}

//出链队
int DeLkqueue(LKQUEUE *Q, ElemType *e)
{
	LQNODEPTR p;
	if(Q->front == NULL)
		return 0;
	p = Q->front;
	Q->front = p->next;
	if(Q->front == NULL)
		Q->rear = NULL;
	*e = p->data;
	free(p);
	return 1;
}

#endif
Grade 8 Result rajsh 说:
2022年8月30日 21:20

Bangladesh Education Board DPE has conducted the class 8th grade of Junior School Certificate Exam and Junior Dakhil Certificate Exam on 1st to 15th November 2022 at all centers in division wise under Ministry of Primary and Mass Education (MOPME), and the class 8th grade terminal examination tests are successfully conducted for all eligible JSC/JDC students for the academic year of 2022. <a href="https://bdjscresult2018.com/">Grade 8 Result rajshahi</a> The Bangladesh government Minister of Secondary Education is going to announce the JSC Result 2022 in student wise for division students in education board wise, and the result documents will be submitted to the Prime Minister of the country after then the result with mark sheet will be announced to public to check the individual result.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter