⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queue.cpp

📁 提供队列数据结构的相关操作
💻 CPP
字号:
// queue.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

typedef int content;

typedef  struct _node
{
	content stcon;
	struct  _node* pnext;
} node;
typedef struct _queue 
{
	node *pfirst;
	node *plast;
	int nlenth;
} queue;

int  Init_queue( queue *pQu)
{
	pQu->pfirst = NULL;
	pQu->plast = NULL;
	pQu->nlenth = 0;
	return 1;
}
int Get_queue(queue *pQu)
{
	node * pexplore = pQu->pfirst;
	if ( pQu->pfirst == NULL )
		return 0;
	for ( ;pexplore != NULL ;)
	{
		printf("%d " , pexplore->stcon);
		pexplore = pexplore->pnext;
	}
	return 1;
}
int Out_queue(queue *pQu)
{
	node * del = pQu->pfirst;
	if ( pQu->nlenth == 0)
		return 0;

	pQu->pfirst = pQu->pfirst->pnext;
	pQu->nlenth--;
	delete (del);
	return 1;
}

int In_queue(queue *pQu,content stin)
{	
	if ( pQu->nlenth == 0)
	{
		pQu->plast = new (node);
		pQu->pfirst = pQu->plast;
	}
	else
	{
		pQu->plast->pnext = new (node );
		pQu->plast = pQu->plast->pnext;
	}
	pQu->plast->stcon = stin;
	pQu->plast->pnext = NULL;
	pQu->nlenth++;
	return 1;
}

int _tmain(int argc, _TCHAR* argv[])
{
	int i = 0;
	int j = 0;
	content nn = 1;
	content get = 0;
	queue Qu;
	Init_queue(&Qu);
	if (0 == Get_queue(&Qu))
		printf( "empty queue! \n");
	if (0 == Out_queue(&Qu))
		printf( " queue is empty! \n");

	In_queue(&Qu,nn); printf( "%d \n" ,Qu.nlenth);
	nn = 2;

	In_queue(&Qu,nn);printf( "%d \n" ,Qu.nlenth);
	nn = 3;
	Out_queue(&Qu);printf( "%d \n" ,Qu.nlenth);
	In_queue(&Qu,nn);printf( "%d \n" ,Qu.nlenth);
	Out_queue(&Qu);printf( "%d \n" ,Qu.nlenth);
	Out_queue(&Qu);printf( "%d \n" ,Qu.nlenth);

	if ( 0 == Get_queue(&Qu))
		printf( " queue is empty! \n");


	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -