线性表链表实现
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