使用C++實(shí)現(xiàn)線性表的基本功能

字號(hào):

#include
    #include
    #include
    typedef int Elemtype;
    //線性表的基本操作
    void Initiallist(Elemtype *L);
    int Isempty(Elemtype *L);
    void ListTraverse(Elemtype *L);
    int NextElem(Elemtype *L);
    int PriorElem(Elemtype *L);
    int LocateElem(Elemtype *L,Elemtype &e);
    void GetElem(Elemtype *L);
    void ListInsert(Elemtype *L);
    void ListDelete(Elemtype *L);
    void ClearList(Elemtype *L);
    const int N=10;
    Elemtype temp;//全局變量!
    void Initiallist(Elemtype *L)
    {
    for(int i=0;i    *(L+i)='#';
    }
    int Isempty(Elemtype *L)
    {
    if(*L=='#')
    return 1;
    else
    return 0;
    }
    void ListTraverse(Elemtype *L)
    {
    static int k;
    if(*(L)==35)
    cout<<"The list is NULL!\n";
    else
    {
    cout<<"The records of the list are:\n";
    for(int i=0;i    {
    if((*(L+i)>32768))
    break;
    else
    cout<<*(L+i)<<" ";
    }
    k++;
    }
    }
    int NextElem(Elemtype *L)
    {
    int index;
    Elemtype e;
    cout<<"Input the records for searching it's next Elem!\n";
    cin>>e;
    index=LocateElem(L,e);
    if(*(L+index+1)>32768)
    cout<<"It has no next Elem!\n";
    else
    cout<    }