#include <iostream>
#include <cstdlib>
using namespace std;
const int flag = -1;
typedef struct SiLinkCirList{
int data;
struct SiLinkCirList *next, *prior;
}*List;
//创建单向循环链表
void creSiLinkCirList(List &L){//system("pause");
int x;
L = (List)malloc(sizeof(SiLinkCirList));
List r = L;
while(cin>>x && x!=flag){
List s = (List)malloc(sizeof(SiLinkCirList));
s->data = x;
r->next = s;
r = s;
}
r->next = L;
}
//输出单向循环链表
void printSiCirList(List L){
List p = L->next;
cout << "当前的单向循环链表为:";
while(p != L){
cout << p->data << " ";
p = p->next;
}
cout << endl;
}
//转换成双向循环链表
void trDouCirList(List &L) {
List p = L;
List s;
while(1){
s = p->next;
s->prior = p;
if(p->next==L)
break;
p = p->next;
}
L->prior = p;
}
//根据prior输出链表
void printByPrior(List L) {
List p = L->prior;
cout << "反向输出的循环链表为:" ;
while(p != L){
cout << p->data << " ";
p = p->prior;
}
cout << endl;
}
int main(){
List L;
cout << "输入单向循环链表元素:";
creSiLinkCirList(L);
printSiCirList(L);
trDouCirList(L);
printByPrior(L);
return 0;
}