朱凯的

IOS工程师

#include <stdio.h>
#include <stdlib.h>
#define OK 1
#define ERROR 0
#define TURE 1
#define FALSE 0
#define LIST_INIT_SIZE 10    // 线性表存储空间的初始分配量
#define LISTINCREMENT 10      // 线性表存储空间的分配增量
#define OVERFLOW -2
typedef int ElemType;
typedef int Status;
typedef struct{
	ElemType *elem;
	int length;
	int listsize;
}SqList;
Status InitList_Sq(SqList *L){
	//构造一个空的线性表L
	L->elem = (ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
	if(!L->elem)
	{
		printf("内存溢出!\n");
		exit(OVERFLOW);
	}
	L->length = 0;
	L->listsize = LIST_INIT_SIZE;
	printf("初始化完成!\n");
	return OK;
}// Initial_Sq
Status ListInsert_Sq(SqList *L, int i, ElemType e)
{
	// 在顺序线性表L中第i个位置之前插入新的元素e
	// i的合法值为1<=i<=ListLength_Sq(L) + 1
	ElemType *newbase;
	ElemType *q;
	ElemType *p;	
	if(i<1 || i>L->length+1)
	{
		printf("插入失败!\n");
		printf("位置信息不合法!\n");
		return ERROR; 		// i的值不合法
	}
	if(L->length >= L->listsize)
	{
		newbase = (ElemType *)realloc(L->elem, (L->listsize + LISTINCREMENT) * sizeof(ElemType)); 
		if(!newbase) exit(OVERFLOW);
		L->elem = newbase;
		L->listsize += LISTINCREMENT;
	}
	q = &(L->elem[i-1]);
	if(0 == L->length)
	{


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值