数据结构C++实现第一发,主要有几部分构成,分别是一个抽象类LinearList.h、数组链表的头文件ArrayList.h以及main.cpp源文件。
LinearList.h文件具体信息如下:
#ifndef INC_01_ARRAYLIST_LINEARLIST_H
#define INC_01_ARRAYLIST_LINEARLIST_H
#include
template
class LinearList {
public:
virtual ~LinearList() {};
virtual bool empty() const = 0;
virtual int size() const = 0;
virtual T& get(int index) const = 0;
virtual int indexof(const T& theElement) const = 0;//first pos
virtual void erase(int index) = 0;
virtual void insert(int index, const T& theElement) = 0;
virtual void output(std::ostream& out) const = 0;
};
#ifndef INC_01_ARRAYLIST_ARRAYLIST_H
#define INC_01_ARRAYLIST_ARRAYLIST_H
#include "LinearList.h"
#include
#include
using namespace std;
template void resizeCapacity(T*& a,int oldCapacity, int newCapacity);
template
class ArrayList :public LinearList {
public:
//iterator
class iterator{
public:
//
typedef bidirectional_iterator_tag iterator_category;
typedef T value_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef T& reference;
//construct
iterator(T* thepos=0) { pos = thepos;}
//operator
T& operator*() const { return *pos;}
T* operator->() const { return &*pos;}
iterator& operator++()
{ ++pos; return *this;}
iterator& operator++(int)
{ iterator old = *this; ++pos; r

本文介绍了如何使用C++实现数据结构中的数组链表,包括一个抽象类LinearList.h、数组链表头文件ArrayList.h以及主程序源文件。内容涵盖数组链表的容量、实际大小、迭代器、添加元素、删除元素、查找元素等操作。同时讨论了构造函数、拷贝构造函数以及析构函数的实现,并实现了容量调整和输出功能。
:数组链表&spm=1001.2101.3001.5002&articleId=53747142&d=1&t=3&u=1549f7659241431495331ad7fe1fbe97)
1120

被折叠的 条评论
为什么被折叠?



