栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

数据结构栈和队列-------------链队列的相关的操作

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

数据结构栈和队列-------------链队列的相关的操作

#include
using namespace std;
typedef struct Node
{
	int data;
	struct Node *next;
}QNode;
typedef struct
{
	QNode *front;
	QNode *rear;
}linkQueue;


void  creatQueue(linkQueue &Q)
{
	Q.front=Q.rear=new QNode; 
	Q.front->next=NULL;
	return;
} 


bool inQueue(linkQueue &Q,int e)
{
	QNode *cp;
	cp=new QNode; 
	cp->data=e;
	cp->next=NULL;
	Q.rear->next=cp;
	Q.rear=cp;
	return true;
}


int outQueue(linkQueue &Q)
{
	float e;
	QNode *cp;
	if(Q.front==Q.rear)
		return 0;
	cp=Q.front->next;
	e=cp->data;
	Q.front->next=cp->next;
	if(Q.rear==cp)
		Q.rear=Q.front;
	delete cp;
	return e;
}


int getQueue(linkQueue Q)
{
	if(Q.front!=Q.rear)
		return Q.front->next->data;
}


int lengthQueue(linkQueue Q)
{
	QNode *cp;
	int i=0;
	cp=Q.front;
	while(cp!=Q.rear) 
	{
		i++;
		cp=cp->next;
	}
	return i;
}


void ouputQueue(linkQueue Q)
{
	QNode *cp;
	cp=Q.front->next;
	while(cp) 
	{
		cout<data<<" ";
		cp=cp->next;
	}
	cout<>ch;
		switch(ch)
		{
			case 1:
				creatQueue(Q);
				cout<<"链队列初始化成功!"<>n;
				for(a;a<=n;a++)
				{
					cout<<"输入入队的第"<>e;
					inQueue(Q,e);
				}
			    cout<<"元素输入成功!"<>e;
				inQueue(Q,e);
				cout<<"元素填充成功!"< 

改代码采用C++进行编译,定义函数进行数据结构中队列的相关操作。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/291746.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号