单链表实现队列
来源:互联网 发布:新东方少儿英语软件 编辑:程序博客网 时间:2024/05/06 22:56
//单链表实现队列#include<new>#include<iostream>template <typename T> struct Node{ T data; Node * next;}; template <typename T> class Queue{ public: typedef Node<T> * PtrToQueue; private: PtrToQueue first; PtrToQueue last; public: bool IsEmpty() { return first->next == NULL; } void MakeEmpty() { if( !IsEmpty() ) while( !IsEmpty() ) Dequeue(); } void Enqueue( T x ) { PtrToQueue tmp; tmp = new Node<T>; tmp->data = x; tmp->next = NULL; last->next = tmp; last = tmp; } T Front() { return first->next->data; } void Dequeue() { PtrToQueue tmp; tmp = first; first = first->next; delete tmp; } T FrontAndDequeue() { T d = Front(); Dequeue(); return d; } int length() { int i; Node<T> * p = first; for(i=0;p!=last;i++,p=p->next); return i; } Queue( ) { first = new Node<T>; first->data = 0; first->next = NULL; last = first; } ~Queue() { MakeEmpty(); delete first; }};
0 0
- 单链表实现队列
- 单链表实现的队列
- 单链表实现队列
- java 单链表实现队列
- 单链表实现队列 栈
- 数据结构-单链表实现队列
- 使用单链表实现链队列
- 数据结构--单链表实现队列1
- 单链表实现一个随机队列
- 实现单链表、栈、队列功能
- 单链表队列的简单实现
- 单链表实现队列链式存储
- 队列实现
- 队列实现
- 队列实现
- 队列实现
- 队列实现
- 队列实现
- 数字通信中的Rice和Nakagami特性研究
- terminator快捷键
- 第八周实践项目2—建立链串的算法库
- Cookie的生命周期问题
- redis 如何处理客户端连接
- 单链表实现队列
- 小谈iOS应用各种状态及转换
- UIScrollView和AutoLayout
- 接着上面sql
- App开发那些事--iOS VS android
- 深度学习、自然语言处理和表征方法
- 关于Anaconda中ipython-notebook的py文件引用问题
- Charles抓取iOS/Android应用网络封包
- sicily 1036. Crypto Columns