线性表的顺序是一组地址连续的存储单元(内存),一次存储线性表的数据元素。
int main()
{
int ar[10]={0,10,20,30,40,50,60,70,80,90,100};
return 0;
}
线性表的这种在计算机内存中表示称做线性表的顺序存储结构或顺序映像,通常这种存储结构的线性表称为顺序表。
随机访问时间复杂度O(1)
插入时间复杂度O(n) 尾插的时间复杂度O(1)
删除时间复杂度O(n) 尾删的时间复杂度O(1)
查找Search时间复杂度O(n)
在计算机内存物理位置相邻来表示线性表中数据元素之间的逻辑关系。
特点:只要确定了存储线性表的起始位置,线性表中任意元素都可随机存取,所以线性表的顺序存储结构是一种随机存取的存储结构。
算法的设计取决于逻辑结构,算法的实现取决于数据元素的物理结构。
typedef 关键字
给已有的类型名取别名
typedef int ElemType;
int main()
{
ElemType ar[]={12,23,34,45,56,67,78,89};
return 0;
}
凡是合法的变量声明都可以加 typedef 将此变量声明转换为类型声明。
u_int8:定义无符号八位二进制整形
unsigned char u_int8;
unsigned short u_int16;
unsigned int u_int32;
unsigned long long u_int64;
//定义无符号整型声明(变量名)
typedef unsigned char u_int8;
typedef unsigned short u_int16;
typedef unsigned int u_int32;
typedef unsigned long long u_int64;
//定义无符号类型声明
int main()
{
u_int8 a,b;
u_int16 x,y;
return 0;
}
typedef int Array[10];//定义一个全局数组(整形类型)
int main()
{
Array ar={12,23,45,56},br={1,2,3,4};
return 0;
}
///
typedef int *PINT
int main()
{
int a=10,b=20;
int *p,s;//*与变量名结合-->p是指针,s是变量名。
PINT x=&a,y=&b; //x,y为整形指针类型
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
#define SEQ_INIT_SIZE 10
typedef int ElemType;
struct SeqList
{
ElemType data[10];
int cursize;
};
//SeqList 放在 struct 之后,当作结构体的名称
int main()
{
struct SeqList myseq;
struct SeqList *p;
struct SeqList seqar[10];
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
#define SEQ_INIT_SIZE 10
struct
{
ElemType data[SEQ_INIT_SIZE];
int cursize;
}SeqList; //SeqList---无名结构体定义的一个全局变量
int main()
{
SeqList myseq;
SeqList *p;
SeqList seqar[10];
}
typedef 重命名后直接作用:定义struct 变量 不用加struct关键字
//线性表的单链表存储结构
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;