池州建行网站wordpress母狗
一.线性表的定义和特点
-  
线性表的定义
 
- 线性表是一种数据结构,它包含了一系列具有相同特性的数据元素,数据元素之间存在着顺序关系。例如,26个英文字母的字符表 ( (A, B, C, ....., Z) ) 就是一个线性表,其中每个字母就是一个数据元素。
 - 在线性表中,每个数据元素可以包含若干个数据项。例如,学生基本信息表中的每个学生可以视为一个数据元素,而这些元素包括学号、姓名、性别、籍贯、专业等数据项。
 -  
2.线性表的特性
 - 在线性表中,虽然每个数据元素可能不同,但是它们都属于同一数据对象,具有相同的特性,且相邻的数据元素之间具有一定的顺序关系。
 -  
3.线性表的长度与空表
 - 线性表的长度由元素的个数 n 决定(n ≥ 0),如果 n = 0 ,则称该线性表为“空表”。
 -  
4.线性表(或线性结构)的特征
 - 存在唯一的一个数据元素被称为“第一个”。
 - 存在唯一的一个数据元素被称为“最后一个”。
 - 除第一个元素外,结构中的每个数据元素都有且只有一个前驱。
 - 除最后一个元素外,结构中的每个数据元素都有且只有一个后继。
 
学习更多嵌入式电子知识,C语言编程技术,欢迎抖音扫码关注

二.线性表之顺序表实现
1.项目结构以及初始代码

初始代码
main.c
#include <stdio.h>int main(int argc, char** argv)
{return 0;
} 
SeqList.h
#ifndef __SEQLIST_H__
#define __SEQLIST_H__#include <stdio.h>#define SEQLIST_INIT_SIZE 8 // 顺序表初始大小typedef int ElemType;typedef struct SeqList
{ElemType* base;// 指向顺序表空间int capacity;// 顺序表容量int size;// 顺序表长度(元素个数)
}SeqList;#endif // !__SEQLIST_H__ 
SeqList.c
#include "SeqList.h" 
2.顺序表初始化
SeqList.h
#ifndef __SEQLIST_H__
#define __SEQLIST_H__#include <stdio.h>
#include <malloc.h>
#include <assert.h>#define SEQLIST_INIT_SIZE 8 // 顺序表初始大小typedef int ElemType;typedef struct SeqList
{ElemType* base;// 指向顺序表空间int capacity;// 顺序表容量int size;// 顺序表长度(元素个数)
}SeqList;void InitSeqList(SeqList* list);#endif // !__SEQLIST_H__ 
main.c
#include <stdio.h>
#include "SeqList.h"int main(int argc, char** argv)
{SeqList mylist;InitSeqList(&mylist);return 0;
} 
SeqList.c
#include "SeqList.h"void InitSeqList(SeqList* list)
{list->base = (ElemType*)malloc(sizeof(ElemType) * SEQLIST_INIT_SIZE);assert(list->base != NULL);list->capacity = SEQLIST_INIT_SIZE;list->size = 0;
} 
3.顺序表操作代码框架
main.c
#include <stdio.h>
#include "SeqList.h"int main(int argc, char** argv)
{SeqList mylist;InitSeqList(&mylist);// 顺序表操作的选择int select = 1;while (select){printf("*********************************************\n");printf("* [1]  push_back         [2]  push_front    *\n");printf("* [3]  show_list         [4]  pop_back      *\n");printf("* [5]  pop_front         [6]  insert_pos    *\n");printf("* [7]  find              [8]  length        *\n");printf("* [9]  delete_pos        [10]  delete_val    *\n");printf("* [11] sort              [12] reverse       *\n");printf("* [13] clear             [14] destroy       *\n");printf("* [0]  quit_system                          *\n");printf("*********************************************\n");printf("请选择:>");scanf("%d", &select);if (select == 0){break;}switch (select){case 1:{break;}case 2:{break;}case 11:{break;}default:{printf("输入的选择错误,请重新输入!\n");break;}}}return 0;
} 
注意:在visual studio2022中,使用scanf()函数获取输入,然后运行项目会报错:

解决方式:



重新运行项目,就不会报错了。
如果你喜欢这篇文章,别忘了收藏、点赞、关注,支持我们为您带来更多精彩内容!❤️🎉
动动手指,做起来吧! 👨💻👩💻,
后面我们还将一起讨论学习:顺序表尾部插入数据并显示,顺序表头部插入数据,顺序表尾部删除数据,顺序表头部删除数据,顺序表指定位置插入数据,顺序表中查找指定的数据是否存在,顺序表的长度,顺序表按位置删除数据,顺序表按值删除数据。。。。。。等等!
