首页 > 其他 > 详细

数据结构----队列

时间:2015-04-29 13:06:41      阅读:81      评论:0      收藏:0      [点我收藏+]
 

1.队列定义

static final int QUEUELEN=15;

class DATA3
{
    String name;
    int age;
}

class SQType
{
    DATA3[] data = new DATA3[QUEUELEN];
    int head;
    int tail;
}

2.初始化队列

SQType SQTypeInit()
{
    SQType q;
    if((q=new SQType())!=null)
    {
        q.head=0;
        q.tail=0;
        return q;
    }
    else
    {
        return null;
    }
}

3.判断空队列

int SQTypeIsEmpty(SQType q)
{
    int temp=0;
    if(q.head==q.tail)    
        temp=1;
        return temp;
}

4.判断满队列

int SQTypeIsFull(SQType q)
{
    int temp=0;
    if(q.tail==QUEUELEN)
        temp=1;
    return temp;
}

5.清空队列

void SQTypeClear(SQType q)
{
    q.head=0;
    q.tail=0;
}

6.释放空间

void SQTypeFree(SQType q)
{
    if(q!=null)
    {
        q=null;
    }
}

7.入队列

int InSQType(SQType q,DATA3 data)
{
    if(q.tail==QUEUELEN)
    {
        System.out.print("队列已满!操作失败!\n");
        return 0;
    }
    else
    {
        q.data[q.tail++]=data;                    //将元素入队列
        return 1;
    }
}

8.出队列

DATA3 OutSQType(SQType q)
{
    if(q.head==q.tail)
    {
        System.out.print("\n队列已空!操作失败!\n");
        return 0;
    }
    else
    {
        return q.data[q.head++];
    }
    return null;
}

9.读结点数据

DATA3 PeekSQType(SQType q)
{
    if(SQTypeIsEmpty(q)==1)
    {
        System.out.print("空队列“);
        return 0;
    }
    else
    {
        return q.data[q.head];
    }
}

10.计算队列长度

int SQTypeLen(SQType q)
{
    int temp;
    temp=q.tail-q.head;
    return temp;
}

  

  

  

  

  

  

  

  

  

数据结构----队列

原文:http://www.cnblogs.com/mathe/p/4465430.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!