Untitled
unknown
plain_text
4 years ago
1.5 kB
8
Indexable
class StringQueue
{
private readonly int maxsize = 20;
private string[] store;
private int head = 0;
private int tail = 0;
private int numItems;
public StringQueue()
{
store = new string[maxsize];
}
public StringQueue(int size)
{
maxsize = size;
store = new string[maxsize];
}
public void Enqueue(string value)
{
numItems++;
store[tail] = value;
if (++tail == maxsize) ;
{
tail = 0;
}
}
public string Dequeue()
{
string headItem;
numItems--;
headItem = store[head];
if (++head == maxsize)
{
head = 0;
}
return headItem;
}
public int Count() // returns number of items in list
{
return numItems;
}
public string Peek()
{
return store[head];
}
public bool IsEmpty()
{
return head == 0;
}
public bool IsFull()
{
return tail == maxsize;
}
}
private void button3_Click(object sender, EventArgs e)
{
label1.Text = myQueue.Peek();
}
Editor is loading...