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

访问计数:26971
本文:208 今天:1 本月 208

本地音乐播放器



 
       队列的链接存储
2007-04-12 晴

出处或者来源:课本

struct LNode
{
ElemType data;
LNode *next;
};

struct LinkQueue
{
LNode *front;
LNode *rear;
};

void InitQueue(LinkQueue &HQ)//初始化链队
{
HQ.front = HQ.rear = NULL;
}

void ClearQueue(LinkQueue &HQ)//清除链队中的所有结点,使之成为空队
{
LNode *p = HQ.front;
while(p != NULL)
{
HQ.front = HQ.front->next;
delete p;
p=HQ.front;
}
HQ.rear = NULL;
}

int QueueEmpty(LinkQueue &HQ)//检查链队是否为空
{
return HQ.front == NULL;
}

ElemType QFront(LinkQueue &HQ)//取队首元素
{
if(HQ.front == NULL)
{
cerr<<"Linked queue is empty!"<<endl;
exit(1);
}
return HQ.froft->data;
}


void QInsert(LinkQueue &HQ, const ElemType &item)//使新元素item的值插入链队
{
LNode *newptr = new LNode;
if(newttr == NULL)
{
cerr<<"Memory allocation failare!"<<endl;
exit(1);
}
newptr->data = item;
newptr->next = NULL;

if(HQ.rear == NULL)
HQ.front = HQ.rear = newptr;//若链队为空,则新结点既是队首结点又是队尾结点
else
HQ.rear = HQ.rear->next = newptr;//依次修改队尾结点的指针使之指向新的队尾结点
}

ElemType QDelete(LinkQueue &HQ)//从队列中删除一个元素
{
if(HQ.front == NULL)
{
cerr<<"Linked queue is empty!"<<endl;
exit(1);
}
Elemtyep temp = HQ.front->data;
LNode *p = HQ.front;
HQ.front = p->next;
if(HQ.front == NULL)
HQ.rear = NULL;
delete p;
return temp;

}.
# posted by kuan @ 2007-04-12 12:49:30 评论(0)
 








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