数据结构严蔚敏 线性表基本操作C++实现

【数据结构(严蔚敏)】 线性表基本操作C++实现(顺序表)


基本代码
vs2017

#pragma once
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
typedef int ElemType;
# define LISTINCREMENT 2;
class Linear_List
{
   
public:
	Linear_List(int listSize);   //初始化空表
	Linear_List(ElemType values[], int Lenth);  //用数组初始化表
	~Linear_List();
	ElemType GetElem(int i);				//返回第I个元素值
	int ListLenth();						//返回表长
	void ListClear();						//将表置空
	bool ListEmpty();						//判断表是否为空
	void ListInsert(int i, ElemType e);		//在i处插入元素e	
	void ListDelete(int i, ElemType &e);	//删除i处元素,用e返回其值
	void PriorElem(ElemType cur_e,ElemType &pre_e);		//返回cur_e的前驱,若无,则失败
	void NextElem(ElemType cur_e, ElemType &next_e);	//返回cur_e的后驱,若无,则失败
	int LocateElem( ElemType e, bool(*compare)(ElemType, ElemType));  //在顺序线性表中查找第一个值与e满足compare()元素的位序
	void ListTraverse(void(*visit)(ElemType));   //对线性表每个元素调用visit()

	
	
private:
	void init(ElemType values[], int n);
protected:
	ElemType * elem;	//存储空间基址
	int lenth;			//当前长度
	int listsize;		//当前分配的存储容量
	
};

Linear_List::Linear_List(int listSize)
{
   
	this->listsize = listSize;
	this->lenth = 0;
	this->elem = new ElemType[listsize];
}

Linear_List::Linear_List(ElemType values[
  • 1
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值