(1)掌握队列的相关概念、特点和基本操作(入队、出队、判队空等)。
队列:只允许在表的一端进行插入,而在另一端删除元素的线性表。
特点:先进先出 (FIFO)
基本操作:
(2)掌握队列的顺序存储和链式存储的实现。
图解:
顺序存储:
入队:
{ if ( ( rear+1)%queuesize = = front ) throw "上溢,无法入队"; base[rear] = x; rear = (rear+1)%queuesize; }
出队:
{ if (front = = rear) throw “下溢,不能出队”; x = base[front]; front = (front+1)%queuesize; return x; }
链式存储(链队列是限制仅在表头删除和在表尾插入的单链表):
入队:
{ s = new Node<T>; s->data = x; s->next = rear->next; rear->next = s; rear = s; }
出队:
{ if ( rear = = front ) throw"下溢"; p = front->next; x = p->data; front->next = p->next; if ( p->next = = NULL) rear = front; delete p; return x; }
(3)了解队列的一些典型应用。
原文地址:https://www.cnblogs.com/yg1024/p/9690575.html
时间: 2024-11-08 22:06:26