首页 > 其他 > 详细

游戏技能设计

时间:2014-03-23 10:14:42      阅读:336      评论:0      收藏:0      [点我收藏+]


//顺序堆栈的操作实现


void StackInitiate(SeqStack *S)
{
S->top=0;
}


int StackNotEmpty(SeqStack S)
{
if(S.top<=0)return 0;
else return 1;
}


int StackPush(SeqStack *S,DataType x)
{
if(S->top>=MaxStackSize)
{
printf("堆栈已满无法插入!\N");
return 0;
}
else
{
S->stack[S->top] = x;
S->top++;
return 1;
}
}


int StackPop(SeqStack *S,DataType *d)
{
if(S->top<=0)
{
printf("堆栈已空无数据元素出栈!\n");
return 0;
}
else
{
S->top--;
*d=S->stack[S->top];
return 1;
}
}


int StackTop(SeqStack S,DataType *d)
{
if(S.top<=0)
{
printf("堆栈已空!\n");
return 0;
}
else
{
*d=S.stack[S.top-1];
return 1;
}
}


//链式堆栈的操作实现


void StackInitiate(LSNode **head)
{
*head=(LSNode*)malloc(sizeof(LSNode));
(*head)->next=NULL;
}


int StackNotEmpty(LSNode *head)
{
if(head->next==NULL) return 0;
else return 1;
}


int StackPush(LSNode *head,DataType x)
{
LSNode *p;
p=(LSNode*)malloc(sizeof(LSNode));
p->data=x;
p->next=head->next;
head->next=p;
return 1;
}


int StackPop(LSNode *head,DataType *d)
{
LSNode *p=head->next;
if(p==NULL)
{
printf("堆栈已空出错!");
return 0;
}
head->next=p->next;
*d=p->data;
free(p);
return 1;
}


int StackTop(LSNode *head,DataType *d)
{
LSNode *p=head->next;
if(p==NULL)
{
printf("堆栈已空出错!");
return 0;
}
*d=p->data;
return 1;
}

游戏技能设计,布布扣,bubuko.com

游戏技能设计

原文:http://blog.csdn.net/hackmind/article/details/21699633

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!