本文实例讲述了c#通过链表实现队列的方法。分享给大家供大家参考。具体实现方法如下:
public class node { public int data { get; set; } public node next { get; set; } public node(int data) { this.data = data; } } public class queue { private node _head; private node _tail; private int _count = 0; public queue() { } public void enqueue(int data) { node _newnode = new node(data); if (_head == null) { _head = _newnode; _tail = _head; } else { _tail.next = _newnode; _tail = _tail.next; } _count++; } public int dequeue() { if (_head == null) { throw new exception("queue is empty"); } int _result = _head.data; _head = _head.next; return _result; } public int count { get { return this._count; } } }
希望本文所述对大家的c#程序设计有所帮助。
您可能感兴趣的文章:
- C#中怎样获取默认配置文件App.config中配置的键值对内容
- C# transfer local file to remote server based on File.Copy
- Unity实现全屏截图以及QQ截图
- c# String扩展 让你在PadLeft和PadRight时不再受单双字节问题困扰
- WinForm自定义函数FindControl实现按名称查找控件
- 在类库或winform项目中打开另一个winform项目窗体的方法
- 超时时间已到。超时时间已到,但是尚未从池中获取连接(超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。)
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论