游客已登陆 (0)未知
笔行证 257310
昵称 kuan 
笔贝 Score1
加为好友 发送短信
<< << 2009 一月 >> >>
123
45678910
11121314151617
18192021222324
25262728293031

访问计数:27084
本文:231 今天:1 本月 231

本地音乐播放器



 
       栈链接存储结构
2007-04-12 晴



void InitStack(LNode *&HS)
{
HS = NULL;
}

void ClearStack(Lnode *& HS)
{
LNode *cp, *np;

cp=HS;//cp指向栈顶
while(cp != NULL)
{
np = cp->next;
delete cp;
cp=np;
}
HS=NULL;
}

int StackEmpty(LNode *HS)
{
return HS == NULL;
}

ElemType Peek(LNode *HS)
{
if(HS == NULL)
{
cerr<<"Linked stack is empty!"<<endl;
exit(1);
}
return HS->data;
}

void Push(LNode *&HS, const Elemtype &item)
{
LNode *newptr = new LNode;
if(newptr == NULL)
{
cerr<<"Memory allocation failare!"<<endl;
exit(1);
}
newptr->data = item;
newptr->next = HS;
Hs = newptr;
}

ElemType Pop(LNode *&HS)
{
if(HS == NULL)
{
cerr<<"Linked stack is empty!"<<endl;
exit(1);
}
LNode *p = HS;
Hs = HS->next;
ElemType temp = p->data;
delete p;
return temp;
}.
# posted by kuan @ 2007-04-12 13:09:45 评论(0)
 








 
笔 名:
*
评 论:
最多1000字。当前字数:0
*
联系方式: