c语言顺序表增删查改源代码,C语言【顺序表】顺序表的初始化,头插,尾插,头删,尾删,增删查改,全删...

#define _CRT_SECURE_NO_WARNINGS 1

#include

#include

#include

#include

#define MAX_SIZE 5

typedef int DataType;

typedef struct SeqList

{

size_t size;

DataType array[MAX_SIZE];

}SeqList;

//void InitSeqList(SeqList* pSeq)

//{

//    assert(pSeq);

//    memset(pSeq->size, 0, sizeof(DataType)*MAX_SIZE);

//    pSeq->size = 0;

//}

//void PushBack(SeqList* pSeq, DataType x)

//{

//    assert(pSeq);

//    if (pSeq->size >= MAX_SIZE)

//    {

//        printf("顺序表已满,无法插入!");

//        return;

//    }

//    pSeq->array[pSeq->size++] = x;

//    pSeq->size++;

//}

//void PopBack(SeqList* pSeq)

//{

//    assert(pSeq);

//    if (pSeq->size <= 0)

//    {

//        printf("顺序表已空,无法删除!");

//        return;

//    }

//    pSeq->size--;

//}

//void PushFront(SeqList* pSeq, DataType x)

//{

//    assert(pSeq);

//    int begin = pSeq->size - 1;

//    int i = 0;

//    if (pSeq->size >= MAX_SIZE)

//    {

//        printf("顺序表已满,无法插入!");

//        return;

//    }

//    for (i = begin; i >= 0; i--)

//    {

//        pSeq->array[begin + 1] = pSeq->array[begin];

//    }

//    pSeq->array[0] = x;

//    pSeq->size++;

//}

//

//void PopFront(SeqList* pSeq)

//{

//    assert(pSeq);

//    int begin = 1;

//    if (pSeq->size <= 0)

//    {

//        printf("顺序表已空,无法删除!");

//        return;

//    }

//    for (begin = 1; begin size; begin ++)

//    {

//        pSeq->array[begin -1] = pSeq->array[begin];

//    }

//    pSeq->size--;

//}

//void Insert(SeqList* pSeq, size_t pos, DataType x)

//{

//    assert(pSeq);

//    int begin = pSeq->size;

//    if (pSeq->size >= MAX_SIZE)

//    {

//        printf("顺序表已满,无法插入!");

//        return 0;

//    }

//    for (; begin > pos;begin--)

//    {

//        pSeq->array[begin] = pSeq->array[begin-1];

//    }

//    pSeq->array[pos] = x;

//    pSeq->size++;

//}

//int Find(SeqList* pSeq,DataType x)

//{

//    int i = 0;

//    for (; i size; i++)

//    {

//        if (pSeq->array[i] == x)

//        {

//            return i;

//        }

//    }

//    return -1;

//}

//void Erase(SeqList* pSeq, size_t pos)

//{

//    assert(pSeq);

//    int begin = 0;

//    if (pSeq->size <= 0)

//    {

//        printf("顺序表已空,无法删除!");

//        return;

//    }

//    assert(pos size);

//

//    for (; begin size; ++begin)

//    {

//        pSeq->array[begin - 1] = pSeq->array[begin];

//    }

//    pSeq->size--;

//}

//int Remove(SeqList* pSeq, DataType x)

//{

//    int pos;

//    assert(pSeq);

//

//    pos = Find(pSeq, 0, x);

//    if (pos != -1)

//    {

//        Erase(pSeq, pos);

//    }

//    return pos;

//}

//void RemoveAll(SeqList* pSeq, DataType x)

//{

//    int count = 0;

//    int begin = 0;

//    assert(pSeq);

//

//    for (; begin size; ++begin)

//    {

//        if (pSeq->array[begin] == x)

//        {

//            ++count;

//        }

//        else

//        {

//            pSeq->array[begin - count] = pSeq->array[begin];

//        }

//    }

//

//    pSeq->size -= count;

//}

void PrintSeqList(SeqList* pSeq)

{

int i = 0;

assert(pSeq);

for (; i size; ++i)

{

printf("%d ", pSeq->array[i]);

}

printf("\n");

}

原文:http://10740184.blog.51cto.com/10730184/1736252

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值