数据结构-C++实现(一):数组链表

数据结构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;
};
    
    
   
   
ArrayList.h文件如下:

#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; return old;} iterator& operator--() { --pos; return *this;} iterator& operator--(int) { iterator old = *this; --pos; return old;} bool operator!=(const iterator rhl) const { return pos != rhl.pos;} bool operator==(const iterator rhl) const { return pos == rhl.pos;} protected: T* pos; }; iterator begin(){ return iterator(element);} iterator end(){ return iterator(element+listsize);} public: //construct copy destroy //ArrayList(int initCapacity = 10); ArrayList(int initCapacity = 10, int size = 0); ArrayList
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值