The queue is characterized by advanced first out, as in daily life in line. The queue has joined the team tail, deletes the element from the team head, obtains the team tail element, obtains the team head element, obtains the queue length, determines whether the queue is empty and so on operation.
Queues can also be implemented with sequential tables, linked lists, but queues are best not implemented in sequential tables, because an element joins the queue and deletes an operation in an element that always causes all elements to move and is extremely inefficient (except for circular queues).
The implementation of the queue is very simple, and the following is implemented using the single linked list described earlier.
Code:
/*
* File:Queue.cs
* Author:zhenxing Zhou
* date:2008-12-07
* blog:http://www.xianfen.net/
*/
Namespace Xianfen.Net.DataStructure
{
public class Queue<t>
{
protected singlelinkedlist<t> m_list;
public bool IsEmpty
{
get {return m_list.isempty;}
}
public int Count
{
get {return m_list.count;}
}
Public Queue ()
{
M_list = new singlelinkedlist<t> ();
}
Public Queue (T t)
{
M_list = new singlelinkedlist<t> (T);
}
Public T dequeue ()
{
T t = M_list.gettail ();
M_list.removetail ();
return t;
}
public void EnQueue (T-t)
{
M_list.addhead (t);
}
Public T Getfront ()
{
return M_list.gettail ();
}
Public T getrear ()
{
return M_list.gethead ();
}
}
}