线性表链表实现

本文档详细介绍了如何使用链表实现线性表,包括`list.h`、`list.cpp`、`Node.h`和`Node.cpp`四个关键文件的实现,以及`demo.cpp`的示例代码展示。
摘要由CSDN通过智能技术生成

线性表链表实现

list.h

#ifndef LIST_H_
#define LIST_H_
#include "Node.h"
class List
{
public:
	List();
	~List();
	void ClearList();
	bool ListEmpty();
	int ListLength();
	bool GetElem(int i, Node *pNode);
	int LocateElem(Node *pNode);
	bool PriorElem(Node *pCurrentNode, Node *pPreNode);
	bool NextElem(Node *pCurrentNode, Node *pNextNode);
	void ListTraverse();
	bool ListInsert(int i, Node *pNode);
	bool ListDelete(int i, Node *pNode);
	bool ListInsertHead(Node *pNode);
	bool ListInsertTail(Node *pNode);
private:
	Node *m_pList;
	int m_iLength;
};


#endif // !LIST_H_


list.cpp

#include "List.h"
#include "Node.h"
#include <iostream>
using namespace std;
List::List()
{
	m_pList = new Node;
	m_pList->data = 0;
	m_pList->next = nullptr;
	m_iLength = 0;
}

List::~List()
{
	ClearList();
	delete m_pList;
	m_pList = nullptr;
}

void List::ClearList()
{
	Node *currentNode = m_pList->next;
	while (currentNode != nullptr) {
		Node *temp = currentNode->next;
		delete currentNode;
		currentNode = temp;
	}
	m_pList->next = nullptr;
	m_iLength = 0;
}

bool List::ListEmpty()
{
	return m_iLength == 0 ? true : false;
}

int List::ListLength()
{
	return m_iLeng
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值