java项目流程图 模版_模板——类模板

//《C++编程——数据结构与程序设计方法》15.8.3

#include

#include

#include "arrayListType.h"

using namespace std;

template

arrayListType::arrayListType(int size)//(int size=100)是错的??

{

if(size<0)

{

cout<

maxSize=100;

}

else

maxSize=size;

length=0;

list=new elemType[maxSize];

}

template

arrayListType::~arrayListType()

{

delete [] list;

}

template

void arrayListType::print() const

{

int i;

for(i=0;i

cout<

cout<

}

template

void arrayListType::insertAt(int location,const elemType& insertItem)

{

int i;

if(location<0||location>=maxSize)

cout<

else

if(length>=maxSize)

cout<

else

{

for(i=length;i>location;i--)

list[i]=list[i-1];

list[location]=insertItem;

length++;

}

}

template

void arrayListType::removeAt(int location)

{

int i;

if(location<0||location>=maxSize)

cout<

else

{

for(i=location;i

list[i]=list[i+1];

length--;

}

}

template

int arrayListType::seqSearch(const elemType& item)

{

int loc;

bool found=false;

for(loc=0;loc

if(list[loc]==item)

{

found=true;

break;

}

if(found)

return loc;

else

return -1;

}

template

void arrayListType::remove(const elemType& removeItem)

{

int loc;

if(length==0)

cout<

else

{

loc=seqSearch(removeItem);

if(loc!=-1)

removeAt(loc);

else

cout<

}

}

template

const arrayListType& arrayListType::operator =(const arrayListType& otherList)

{

if(this!=&otherList)

{

if(maxSize!=otherList.maxSize)

cout<

else

{

int j;

maxSize=otherList.maxSize;

length=otherList.length;

list=new elemType[maxSize];

if(length!=0)

for(j=0;j

list[j]=otherList.list[j];

}

return *this;

}

}

//头文件arrayListType.h,据说类模板的实现部分只能做到.h   文件中

#ifndef _ARRAYLISTTYPE_H

#define _ARRAYLISTTYPE_H

template

class arrayListType

{

public:

const arrayListType& operator=(const arrayListType&);

//  bool isEmpty();

//  bool isFull();

//  int ListSize();

//  int ListSize();

//  int maxListSize();

void print() const;

//  bool isItemAtEqual(int location,const elemType& item);

void insertAt(int location,const elemType& insertItem);

//  void insertEnd(const elemType& insertItem);

void removeAt(int location);

//  void retrieveAt(int location,elemType& retItem);

//  void replaceAt(int location,const elemType& repItem):

//  void clearList();

int seqSearch(const elemType& item);

//  void insert(const elemType& insertItem);

void remove(const elemType& removeItem);

arrayListType(int size=100);

//  arrayListType(const arrayListType& otherList);

~arrayListType();

protected:

elemType *list;

int length;

int maxSize;

};

template

arrayListType::arrayListType(int size)//(int size=100)是错的??

{

if(size<0)

{

cout<

maxSize=100;

}

else

maxSize=size;

length=0;

list=new elemType[maxSize];

}

template

arrayListType::~arrayListType()

{

delete [] list;

}

template

void arrayListType::print() const

{

int i;

for(i=0;i

cout<

cout<

}

template

void arrayListType::insertAt(int location,const elemType& insertItem)

{

int i;

if(location<0||location>=maxSize)

cout<

else

if(length>=maxSize)

cout<

else

{

for(i=length;i>location;i--)

list[i]=list[i-1];

list[location]=insertItem;

length++;

}

}

template

void arrayListType::removeAt(int location)

{

int i;

if(location<0||location>=maxSize)

cout<

else

{

for(i=location;i

list[i]=list[i+1];

length--;

}

}

template

int arrayListType::seqSearch(const elemType& item)

{

int loc;

bool found=false;

for(loc=0;loc

if(list[loc]==item)

{

found=true;

break;

}

if(found)

return loc;

else

return -1;

}

template

void arrayListType::remove(const elemType& removeItem)

{

int loc;

if(length==0)

cout<

else

{

loc=seqSearch(removeItem);

if(loc!=-1)

removeAt(loc);

else

cout<

}

}

template

const arrayListType& arrayListType::operator =(const arrayListType& otherList)

{

if(this!=&otherList)

{

if(maxSize!=otherList.maxSize)

cout<

else

{

int j;

maxSize=otherList.maxSize;

length=otherList.length;

list=new elemType[maxSize];

if(length!=0)

for(j=0;j

list[j]=otherList.list[j];

}

return *this;

}

}

#endif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值