- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
#include stdio.h
#include stdlib.h
#include string.h
#define Error( Str ) FatalError( Str )
#define FatalError( Str ) fprintf( stderr, %s\n, Str ), exit( 1 ) #define MAX_STRING_LENGTH 1000
#define MaxElements 1000
#define MinQueueSize ( 5 )
typedef int ElementType;
typedef struct TreeNode *Position; typedef struct TreeNode *SearchTree; typedef Position DataType;
typedef struct QueueRecord *Queue; struct TreeNode
{
ElementType Element;
SearchTree Left;
SearchTree Right;
};
struct QueueRecord
{
int Capacity;
int Front;
int Rear;
int Size;
DataType *Array;
};
int IsEmpty( Queue Q ) {
return Q-Size == 0; }
int IsFull( Queue Q )
{
return Q-Size == Q-Capacity;
}
void MakeQueueEmpty( Queue Q ) {
Q-Size = 0;
Q-Front = 1;
Q-Rear = 0;
Queue CreateQueue( int size ) {
Queue Q;
if( size MinQueueSize )
Error( Queue size is too small );
Q = malloc( sizeof( struct QueueRecord ) );
if( Q == NULL )
FatalError( Out of space!!! );
Q-Array = malloc( sizeof( DataType ) * size );
if( Q-Array == NULL ) FatalError( Out of space!!! );
Q-Capacity = size;
MakeQueueEmpty( Q );
return Q;
}
void DisposeQueue( Queue Q )
{
if( Q != NULL )
{
free( Q-Array );
free( Q );
}
}
static int Succ( int Value, Queue Q )
{
if( ++Value == Q-Capacity )
Value = 0;
return Value;
}
void Enqueue( DataType X, Queue Q ) {
if( IsFull( Q ) )
Error( Full queue );
else
{
Q-Size++;
Q-Rear = Succ( Q-Rear, Q );
Q-Array[ Q-Rear ] = X;
DataType FrontAndDequeue( Queue Q )
{
DataType X = 0;
if( IsEmpty( Q ) )
Error( Empty queue );
else
{
Q-Size--;
X = Q-Array[ Q-Front ];
Q-Front = Succ( Q-Front, Q );
}
return X;
}
SearchTree MakeTreeEmpty( SearchTree T )
{
if( T != NULL )
{
MakeTreeEmpty( T-Left );
MakeTreeEmpty( T-Right ); free( T );
}
return NULL;
}
SearchTree Insert( ElementType X, SearchTree T )
{
if( T == NULL )
{
T = malloc( sizeof( struct TreeNode ) );
if( T == NULL )
FatalError( Out of space!!! );
else
{
T-Element = X;
T-Left = T-Right = NULL;
}
}
else if( X T-Element ) T-Left = Insert( X, T-Left );
else if( X T-Elem
您可能关注的文档
最近下载
- DB32_T2880-2016:光纤传感式桥隧结构健康监测系统设计、施工及维护规范.pdf VIP
- 中医个人简历【范本模板】.pdf VIP
- 20191117-技术指标系列报告之六:RSRS择时:回顾与改进-光大证券.pdf VIP
- 《煤矿瓦斯抽采基本指标GB+41022-2021》详细解读.pdf
- 行道树种植养护技术规范.docx VIP
- 十年(2016-2025)高考英语真题分类汇编:专题02 代词、介词和介词短语(全国通用)(解析版).docx VIP
- 《低空无人驾驶航空器起降场地安全通用要求》.docx VIP
- 第二单元银屏乐声《辛德勒的名单》+课件+2025-2026学年人音版(简谱)八年级音乐上册.pptx VIP
- 2025年全国事业单位事业编联考D类《职测》部分真题及答案(3月29日).docx VIP
- 化工厂基础工程施工方案.pdf
原创力文档


文档评论(0)