/*实验要求 :(1)基本要求 : 实现如下 五个函数
(2)拓展:a 程序的健壮性 。
b 对于插入,删除位置 若不合法请给出适当的提醒 。
c 排序后再进行后续操作。*/
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define list_init 10
#define list_increase 5
#define overflow -2
#define ok 1
#define error 0
typedef int status;
typedef struct
{
int *elem;
int length;
int listsize;
}sqlist;
status initlist(sqlist &L) // 1 构造一个空的线性表
{
L.elem=(int *)malloc(list_init*sizeof(int));
if(!L.elem)
{
printf("#####存储分配失败#####\n");
exit(overflow); //存储分配失败
}
L.length=0;
L.listsize=list_init; //初始存储容量
return ok;
}
status listinsert(sqlist &L,int i,int e) // 2 插入元素
{
int *p,*q;
if(i<1||i>L.length+1)
{
printf("###输入的位置不合法###\n");
printf("------------------------------\n");
return error; // i 值不合法
}
if(L.length>=L.listsize) //当前存储空间已满,增加分配
{
int *newbase=(int *)realloc(
数据结构 顺序表 上机实验 1
最新推荐文章于 2024-06-04 23:10:08 发布