此程序是在看过郝斌老师的数据结构与算法的视频后,自己用C语言实现的。整个程序比较简单,适合入门数据结构时练手。
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define true 1
#define false 0
typedef int bool;
struct Array
{
int *arrBase;
int maxlen; //最大长度
int len; //当前有效长度
};
// 函数声明
void create_arr(struct Array *arr,int maxlen);// 构造一个list
bool append_arr(struct Array *arr,int value); // 向list最后一个位置添加元素
bool insert_arr(struct Array *arr,int pos,int value);//在第pos个位置上插入一个元素
bool delete_arr();
bool isEmpty(struct Array *arr);
bool isFull(struct Array *arr);
void show_arr(struct Array *arr);
void inverse_arr(struct Array *arr);
void sort_arr(struct Array *arr);
void create_arr(struct Array *arr,int maxlen)
{
arr->arrBase = (int *)malloc(sizeof(int)*maxlen);
arr->len=0;
arr->maxlen=maxlen;
}
bool append_arr(struct Array *arr,int value)
{
if(isFull(arr