欢迎使用CSDN-markdown编辑器

/* 动态的循序表的操作集合*/
/* 数据的结构  
                struct  seqlist 
                {
                    int data[Maxsize];
                    int cur;
                    int Maxsize;
                }
 */
#include<stdio.h>
#include<stdlib.h>
#include"seqlist_operation.h"

// initialization
PSeqL ini (int maxsize)
{
    PSeqL p;

    if( (p = (PSeqL )malloc((3)*sizeof(int)))  == NULL)
            return NULL;

    if( (p->data = (int *)malloc(maxsize * sizeof(int))) == NULL)
            return NULL;

    p->cur = 0;
    p->Maxsize = maxsize;

    return p;
}

//  sequential list inputed data
void Input(int x, const PSeqL const p)
{
    if(IsFull(p))
        return ;
    p->data[p->cur] = x;
    p->cur++;
}

//  whether sequential list is empty; is return 1; no return 0;
int IsEmpty(const PSeqL const p)
{
    if(0 == p->cur)
        return 1;
    else
        return 0;
}

//  whether sequential list is full
int IsFull(const PSeqL const p)
{
    if(p->cur == p->Maxsize)
        return 1;
    else
        return 0;
}

// search a data in the list
int Search(const int x,const PSeqL const p)
{
    int site;

    for(site = 0; site<p->Maxsize ; site++)
    {
        if(x == p->data[site])
                return (site+1);
    }

        return 0;
}

// get the length of the list
int Length(const PSeqL const p)
{
    return (p->cur);
}

// copy a sequential list
PSeqL Copy(const PSeqL const p)
{
    PSeqL c;
    int i;

    if( (c = ini(p->Maxsize)) == NULL)
            return NULL;

    for(i = 0; i<p->Maxsize; i++)
    {
        c->data[i] = p->data[i];
    }

    c->cur = p->cur;

    return c;
}

// insert a data
int Insert (const int x,const int site, PSeqL const p)
{
    int i;

    if(IsFull(p))
            return 0;

    for(i = p->cur ; i>=site; i--)
    {
        p->data[i] = p->data[i-1];
    }

    p ->data[i] = x;
    p->cur++;
    return 1;
}

// remove a data from list
int Remove (const int site, PSeqL const p)
{
    int i;
    if (IsEmpty(p))
            return 0;

    for(i = site; i<p->cur; i++)
    {
        p->data[i-1] = p->data[i];
    }

    p ->cur--;
    return 1;
}

// putlist 
void PutList (const PSeqL const p)
{
    int i;

    for(i = 0; i<p->cur; i++)
    {
        printf("%d ", p->data[i]);
    }
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值