常用数据结构

顺序表 SeqList

1
2
3
4
5
6
7
typedef int DataType;
typedef struct SeqList
{
DataType* a;
int size; //数据的个数
int capacity; //容量大小
}SeqList;

需要实现的操作:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//初始化
void SeqListInit(SeqList* ps);
//尾插
_Bool SeqListPushBack(SeqList* ps, DataType x);
//头插
_Bool SeqListPushFront(SeqList* ps, DataType x);
//打印
void SeqListPrint(SeqList* ps);
//检查是否需要扩容
_Bool SeqListCheckCapacity(SeqList* ps);
// 顺序表查找
int SeqListFind(SeqList* ps, DataType x);
// 顺序表在pos位置插入x
void SeqListInsert(SeqList* ps, int pos, DataType x);
// 顺序表删除pos位置的值
void SeqListErase(SeqList* ps, int pos);

链表

1
2
3
4
5
typedef int DataType;
typedef struct LinkList{
DataType data;
struct LinkList* next; // 下一个结点
}LinkList;

需要实现的功能:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 初始化链表
void LinkListInit(LinkList* L);
//打印
void LinkListPrint(LinkList* L);
//求单链表的长度
int LinkListLength(LinkList* L);
//尾插
_Bool LinkListPushBack(LinkList* L, DataType x);
//头插
_Bool LinkListPushFront(LinkList* L, DataType x);
// 插入操作 在第i个结点插入x
_Bool LinkListInsert(LinkList* L, int i, DataType x)
//删除操作:将单链表中的第i个结点删除
void LinkListDelete(LinkList* L, int i)
//按位查找:查找在单链表L中第i个位置的结点
LinkList* LinkListGetElem(LinkList* L, int i)

栈(Stack)是只允许在一端进行插入或删除操作的线性表

1
2
3
4
5
6
typedef int DataType;
typedef struct StackNode
{
DataType data;
struct node *next;
} StackNode; //定义结点和头指针类型名

需要实现的操作:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//初始化链栈
void Init_LinkStack(StackNode* s);
//销毁栈操作
void DestortStack(StackNode* s);
//判栈空
_Bool StackEmpty(StackNode* s);
//入栈
void Push(StackNode* s,DataType e);
//出栈
DataType Pop(StackNode* s);
//查看栈顶元素
int GetTop(StackNode* s)
//链表的显示
void Display_LinkStack(StackNode* s)
//清空栈
void ClearStack(StackNode* s);

队列

只能在表的一端进行插入运算,在表的另一端进行删除运算的表
(头删尾插)

入队是在队尾进入 出队是在对头出去

1
2
3
4
5
typedef int DataType;

struct Queue{
DataType data;
}

需要实现的操作:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//初始化队列
_Bool InitQueue(SQueue* queue)
//判断队空
_Bool QueueEmpty(SQueue* queue)
//判断队满
_Bool QueueFull(SQueue* queue)
// 销毁队列
DestroyQueue();
// 清空队列
ClearQueue();
// 查看队列元素个数
QueueLength();
// 查看队列的对头元素
GetHead();
//入队
void EnQueue(SQueue* queue,DataType e)
//出队
DataType DeQueue(SQueue* queue)
// 打印队列所有元素
void PrintQueue(SQueue* queue)