⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paint.h

📁 C++编写的一个模拟短信接受予删除短信
💻 H
字号:
#ifndef PAINT_H
#define PAINT_H
#include <stdlib.h>
#include <stdio.h>

#define	ERROR					-1
#define	OK						0
#define	OUT_OF_MEM			20

typedef	int	Status;
typedef	int		LValueType;

typedef	struct _LListNode	LListNode; //节点类型
typedef	struct _LList		LList; //线性表类型

typedef	LListNode*			Position; //节点位置类型
typedef	int					Rank; //节点秩类型

/*
* 常量定义
************************************************************************/
#define	LIST_INIT_SIZE			101 //存储空间的初始分配量

/*
* 类型定义
************************************************************************/

typedef	struct _LListNode	{
	LValueType		value; //数据域
	LList*			list; //指向所属的线性表
}	LListNode; //线性表节点

typedef	struct _LList {
	int				id; //标识
	Position			elem; //存储空间的基地址
	int				length; //当前实际长度
	int				capacity; //当前分配的存储容量(以sizeof(LValueType)为单位)
}	LList; //线性表

/*
*	构造一个空的线性表(用id标识)
* O(1) —— 不计申请空间
************************************************************************/
LList*		ListInit(int	id)
{
	static		int sid = 0;
	LList*		L = (LList*)malloc(sizeof(LList));

	if (id > sid)	sid = id;
	else				id = sid++;

#if defined(VERBOSE)
	printf("Creating List%d...", id);
#endif

	L->elem = (Position) malloc(LIST_INIT_SIZE * sizeof(LListNode));
	if (!L->elem)	exit(OUT_OF_MEM);	//存储空间分配失败
	L->length		= 0; //空表长度为0
	L->capacity	= LIST_INIT_SIZE; //初始存储容量
	L->id			= id;
	for (Rank i=0; i<L->capacity; i++)	L->elem[i].list = L;

#if defined(VERBOSE)
	printf("done\n");
#endif

	return(L);
}

/*
*	销毁线性表L
* O(1) —— 不计申请空间
************************************************************************/
Status		ListDestroy(LList*	L)
{
#if defined(VERBOSE)
	printf("Destroying List%d of size%d ...", L->id, L->length);
#endif

	free(L->elem);	free(L);	L = NULL;

#if defined(VERBOSE)
	printf("done\n");
#endif
	return(OK);
}

/*
*	返回元素的数据域
* 0 <= i < L->length
* O(1)
************************************************************************/
LValueType	ListGetValue(LList*	L, Rank	i) //O(1)时间
{	return L->elem[i].value;	}


/*
*	设置元素的数据域
* O(1)
************************************************************************/
void ListSetValue(LList*	L, Rank	i,	LValueType	value)
{
	L->elem[i].value = value;
}


#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -