LinkedQueue的实现 - 中国WEB开发者网络 (http://www.webasp.net) -- 技术教程 (http://www.webasp.net/article/) --- LinkedQueue的实现 (http://www.webasp.net/article/5/4183.htm) |
| -- 作者:未知 -- 发布日期: 2003-07-12 |
| public class LinkedQueue { private class Node { public object Data; public Node Link; } private Node front; private Node rear; public LinkedQueue() { } public bool IsEmpty { get { return front == null; } } public bool IsFull { get { Node p; try { p = new Node(); return false; } catch { return true; } } } public object First { get { if(IsEmpty) { throw new Exception("Queue is empty."); } return front.Data; } } public object Last { get { if(IsEmpty) { throw new Exception("Queue is empty."); } return rear.Data; } } public LinkedQueue Add(object x) { Node p; // create node for new element p = new Node(); p.Data = x; p.Link = null; if(front != null) // queue not empty { rear.Link = p; } else // queue empty { front = p; } rear = p; return this; } public object Delete() { Node p; object x; if(IsEmpty) { throw new Exception("queue is empty."); } // save element in first node x = front.Data; // delete first node p = front; front = front.Link; p = null; return x; } } |
| webasp.net |