Initialize
static final int QUEUELEN=50;
class DATA4
{
string name;
int age;
}
class SQType
{
DATA4[] data = new DATA4[QUEUELEN]
int head;
int tail;
}
SQType SQTypeInit()
{
SQType q;
if((q = new SQType())!=null)
{
q.head=0;
q.tail=0;
return q;
}
else
{
return null;
}
}
Is empty?
int SQTypeIsEmpty(SQType q)
{
int temp=0;
if(q.head==q.tail)
{
temp=1;
return(temp);
}
}
Is Full?
int SQTypeIsFull(SQType q)
{
int temp=0;
if(q.tail==QUEUELEN)
{
temp=1;
return (temp);
}
}
Clear data
void SQTypeClear(SQType q)
{
q.head=0;
q.tail=0;
}
Free memory
void SQTypeFree(SQType q)
{
if(q!=null)
{
q=null;
}
}
Add in quue
int InSQType(SQType q,DATA4 data)
{
if(q.tail==QUEUELEN)
{
System.out.println("memory full");
return 0;
}
else
{
q.data[q.tail++]=data;
return 1;
}
}
delete in queue
DATA4 OutSQType(SQType q)
{
if(q.head==q.tail) {
System.out.println("empty queue");
System.exit(0);
}else
{
return q.data[q.head++];
}
return null;
}
peek
DATA PeekSQType(SQType q)
{
if(SQTypeIsEmpty(q)==1)
{
System.out.println("empty queue");
return null;
}
else
{
return q.data[q.head];
}
}
calculate the length of queue
int SQTypeLen(SQType q)
{
int temp;
temp=q.tail-q.head;
return(temp);
}