#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<assert.h> #include<stdlib.h> #include<string.h> #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 < pSeq->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 < pSeq->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 < pSeq->size); // // for (; begin < pSeq->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 < pSeq->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 < pSeq->size; ++i) { printf("%d ", pSeq->array[i]); } printf("\n"); }
C语言【顺序表】顺序表的初始化,头插,尾插,头删,尾删,增删查改,全删
原创
©著作权归作者所有:来自51CTO博客作者韩静静的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
简单的尾插法实现单链表
尾插法建立单链表
结点 头结点 链表 -
1.顺序表的实现——C语言
顺序表各种操作的代码实现
顺序表 冒泡排序 算法 随机数 -
顺序表的动态分配(C语言版)
顺序表的动态分配代码实录
顺序表 动态分配 C语言 -
C语言:单链表的实现(包括:尾插、尾删、头插、头删、指定位置插入、长度、打印)
单链表的算法实现:包括尾插、尾删、头插、头删、指定位置插入、长度、打印
C语言 单链表的实现 尾插 尾删 头插 -
【数据结构入门】顺序表(SeqList)详解(初始化、增、删、查、改)
【数据结构入门】顺序表(SeqList)详解(初始化、增、删、查、改)
顺序表 数据结构 c语言 SeqList 线性表 -
链式存储(头插法、尾插法)
#include "stdio.h" #incl
结点 数据 线性表 #include 头结点