Definition:
basic operations:
- Create: create an empty linear list
- Clear: delete all the data in the linear list. The length of the list becomes 0
- GetLength: get the length of the linear list( the number of data)
- 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
- 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
- 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)
- Visit( i): return the value of the ith elements in the linear list
- 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