Data structure (C #): Queues

Source: Internet
Author: User
Tags count

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 ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.