General Introduction to Linear List

Definition:
basic operations:

  1. Create: create an empty linear list
  2. Clear: delete all the data in the linear list. The length of the list becomes 0
  3. GetLength: get the length of the linear list( the number of data)
  4. Insert( i, x): change ( a0, a1, …, ai-1, ai, ai+1, …, an-1) into ( a0, a1, …, ai-1, x, ai, ai+1, …, an-1) 0<=i<=n
  5. Delete( i, x): change ( a0, a1, …, ai-1, ai, ai+1, …, an-1) into ( a0, a1, …, ai-1, ai+1, …, an-1) 0<=i<=n-1
  6. Search( x): check for the presence of elements with the value of x. If search fails, return a special symbol( like -1). If they exist, return the position of the elements( order in the linear list)
  7. Visit( i): return the value of the ith elements in the linear list
  8. Traverse: visit every elements in order

Using the object-oriented programming method, we have the abstract base class of linear list as follows:

#ifndef LINEAR_LIST_ABSTRACT_BASE_CLASS_OF_LINEAR_LIST_H
#define LINEAR_LIST_ABSTRACT_BASE_CLASS_OF_LINEAR_LIST_H
template<class elemType>
class list{
public:
    virtual void Clear()=0;
    virtual int GetLength() const =0;
    virtual void Insert(int i, const elemType&x)=0; //insert an element at the ith position
    virtual void Delete(int i)=0;  //delete the ith element, the (i+1)th element becomes the ith element
    virtual int Search(const elemType&x) const=0;  //return the position of the first one found
    virtual elemType Visit(int i) const =0;
    virtual void Traverse() const =0;
    virtual ~list(){}; //not "=0"
                      //create an empty linear list can be realize in every concrete class
};
#endif //LINEAR_LIST_ABSTRACT_BASE_CLASS_OF_LINEAR_LIST_H
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值