/*--------------单链表改为双链表-----------*/
#include <iostream.h>
#define ok 1
#define error 0
typedef int elemtype;
typedef struct lnode{
lnode *pre;
lnode *next;
elemtype data;
} lnode,*linklist;
bool createlist(linklist &head,int n){
linklist p;
head=new lnode;
head->next=NULL;
if(n<0) return error;
for(int i=0;i<n;i++){
p=new lnode;
cin>>p->data;
p->next=head->next;
head->next=p;
}
return ok;
}
bool printlist(linklist head){
linklist p;
p=head->next;
while(p!=NULL){
cout<<p->data;
p=p->next;
}
return ok;
}
bool changelist(linklist &head){
linklist p,q;
p=head;
q=head->next;
while(q!=NULL){
q->pre=p;
q=q->next;
p=p->next;
}
head->pre=p;
//test
cout<<"/ntest"<<endl;
while(p!=head){
cout<<p->data;
p=p->pre;
}
return ok;
}
void main(){
linklist head;
int n;
cout<<"lnodes number:";
cin>>n;
createlist(head,n);
printlist(head);
changelist(head);
cout<<endl;
}