标题:那位好心人帮忙给我写写这个程序的主函数
取消只看楼主
快乐小车车
Rank: 1
等 级:新手上路
帖 子:10
专家分:3
注 册:2012-2-29
结帖率:50%
已结贴  问题点数:20 回复次数:0 
那位好心人帮忙给我写写这个程序的主函数
#include<iostream.h>
template <class T>
class LinearList
{
public:
    virtual bool IsEmpty() const=0;
    virtual int Length() const=0;
    virtual bool Find(int i,T& x) const=0;
    virtual int Search(T x) const=0;
    virtual bool Insert(int i,T x)=0;
    virtual bool Delete(int i)=0;
    virtual bool Update(int i,T x)=0;
    virtual void Output(ostream& out)const=0;
protected:
    int n;
};
#include"Linearlist.h"
template <class T>
class SequList:public LinearList<t>
{
    public:
        SeqList(int mSize);
        ~SeqList(){delete [] element;}
        bool IsEmpty() const;
        int Length() const;
        bool Find(int i,T& x) const;
        int Search(T x) constSearch(T x) const;
        bool Insert(int i,T x);
        bool Delete(int i);
        bool Update(int i,T x);
        void Output(ostream& out)const;
    private:
        int maxLength;
        T *elements;
};
template <class T>
SequList<T>::SequList(int mSize)
{
    maxLength=mSize;
    elements=new T[maxLength];
    n=0;

}
template <class T>
bool SequList <T>::IsEmpty() const
{
    return n==0;
}
template <class T>
int SeqList<T>::Length() const
{
    return 0;
}
template <class T>
bool SeqList<T>::Find(int i,T& x) const
{
    if(i<0||i>n-1)
    {
        cout<<"out of Bounds"<<endl;
        return false;
    }
    x=elements[i];
    return true;
}
template <class T>
int SeqList<T>::Search(T x) const
{
    for(int j=0;j<n;j++)
        if(elements[j]==x)
            return j;
        return -1;
}
template <class T>
bool SeqList<T>::Insert(int i,T x)
{
    if(i<-1||i>n-1)
    {
        cout<<"out of Bounds"<<endl;
        return false;
    }
    if(n==maxLength)
    {
        cout<<"OverFlow"<<endl;
        return false;
    }
    for(int j=n-1;j>i;j--)
        elements[j+1]=elements[j];
    elemets[i+1]=x;
    n++;
    return true;
}
template <class T>
bool SeqList<T>::Delete(int i)
{
    if(!n)
    {
       cout<<"UnderFlow"<<endl;
        return false;
    }
    if(i<0||i>n-1)
    {
        cout<<"out of Bounds"<<endl;
        return false;
    }
    for(int j=i+1;j<n;j++)
        elements[j-1]=elements[j];
    n--;
    return true;
}
template <class T>
bool SeqList<T>::Update(int i,T x)
{
    if(i<0||i>n-1)
    {
        cout<<"out of Bounds"<<endl;
        return false;
    }
    elements[i]=x;
    return true;
}
template <class T>
void SeqList<T>::Output(ostream& out)const
{
    for(int i=0;i<n;i++)
        out<<elements[i]<<' ';
    out<<endl;
}
搜索更多相关主题的帖子: class 函数 include public 
2012-03-26 21:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-364408-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.396020 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved