锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
#include "iostream.h"
#include "string.h"
typedef char ElemType;
typedef struct LNode{
ElemType data;
struct LNode *next;
}LNode,*Link;
class LinkList
{
private:
Link head;
public:
LinkList(){}
LinkList(ElemType a[]);
void CreateLinkList();
void inver();
ElemType get(int i);
Status insert(int loc,ElemType e);
ElemType del(int i);
void print();
void MergeList(LinkList la,LinkList lb);
};
LinkList::LinkList(ElemType a[])
{
int n=strlen(a),i;
Link p;
head=new LNode;
head->next=NULL;
for(i=n-1;i>=0;i--)
{
p=new LNode;
p->data=a[i];
p->next=head->next;
head->next=p;
}
};
void LinkList::print()
{
Link p=head->next;
while(p)
{
cout<<p->data<<"->";
p=p->next;
}
cout<<"NULL"<<endl;
};
void LinkList::CreateLinkList()
{
int n;
cout<<"璇瘋緭鍏ヤ綘瑕佹瀯寤虹殑琛ㄧ殑闀垮害:";
cin>>n;
ElemType *e;
e=new ElemType[n];
cin>>e;
int i;
Link p;
head=new LNode;
head->next=NULL;
for(i=n-1;i>=0;i--)
{
p=new LNode;
p->data=e[i];
p->next=head->next;
head->next=p;
}
}
ElemType LinkList::get(int i)
{
int cnt=1;
Link p=head->next;
while(cnt!=i)
p=p->next;
return p->data;
}
Status LinkList::insert(int loc,ElemType e)
{
Link p=head;
int j=0;
while(p&&j++<loc-1) p=p->next;
if(!p||j>loc-1) return ERROR;
Link s=new LNode;
s->data=e;
s->next=p->next;
p->next=s;
return OK;
}
#define LIST_INIT_SIZE 100
template <class ElemType>
class SqList
{
private:
ElemType *elem;
int length;
int listsize;
public:
SqList(int max=LIST_INIT_SIZE);
~SqList(){delete[] elem;}
void ClearList();
Status input(int n);
Status output();
Status ListEmpty();
int ListLength();
ElemType GetElem(int i);
Status NextElem(ElemType i,ElemType &next_e);
Status ListInsert(int i,ElemType e);
Status ListDelete(int i,ElemType &e);
Status inver();// 閫嗙疆
//Status MergeList(SqList La,SqList Lb);
};
template <class ElemType> SqList<ElemType>::SqList(int max)
{
listsize=max;
length=0;
elem=new ElemType[listsize];
};
template <class ElemType> void SqList<ElemType>::ClearList()
{
delete[] elem;
elem=new ElemType[listsize];
length=0;
};
template <class ElemType> Status SqList<ElemType>::input(int n)
{
if(n<=0) return ERROR;
for(int i=0;i<n;i++)
{
cout<<"杈撳叆絎?<<i+1<<"涓暟:";
cin>>elem[i];
}
length=n;
return OK;
};
template <class ElemType> Status SqList<ElemType>::output()
{
if(length==0) return ERROR;
else
{
for(int i=0;i<length;i++)
{
cout<<elem[i]<<"->";
}
cout<<"NULL"<<endl;
}
return OK;
};
template <class ElemType> Status SqList<ElemType>::ListEmpty()
{
if(length==0) return TRUE;
else return FALSE;
};
template <class ElemType> int SqList<ElemType>::ListLength()
{
return length;
};
template <class ElemType> ElemType SqList<ElemType>::GetElem(int n)
{
ElemType e;
if(length==0) return ERROR;
if(n<1||n>ListLength()) return OVERFLOW;
e=elem[n-1];
return e;
};
template <class ElemType> Status SqList<ElemType>::NextElem(ElemType loc_e,ElemType &next_e)
{
if(length==0) return ERROR;
for(int i=1;loc_e!=elem[i-1];i++);
if(i==length) return OVERFLOW;
next_e=elem[i];
return OK;
};
template <class ElemType> Status SqList<ElemType>::ListInsert(int i,ElemType e)
{
if(i<1||i>length) return ERROR;
if(listsize==length) return OVERFLOW;
for(int n=length-1;n>=i-1;n--)
elem[n+1]=elem[n];
elem[i-1]=e;
length++;
return OK;
};
template <class ElemType> Status SqList<ElemType>::ListDelete(int i,ElemType &e)
{
if(i<1||i>length) return ERROR;
e=elem[i-1];
for(int n=i-1;n<length-1;n++)
elem[n]=elem[n+1];
length--;
return OK;
};
template <class ElemType> Status SqList<ElemType>::inver()
{
int i,m,n;
ElemType temp;
n=length;
m=n/2;
for(i=0;i<m;i++)
{
temp=elem[i];elem[i]=elem[n-i-1];elem[n-i-1]=temp;
}
return OK;
};