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