## UVa11925 生成排列（Generating Permutations）---双向循环链表

https://vjudge.net/problem/UVA-11925

``````#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <sstream>
#include <malloc.h>
#include <iostream>
using namespace std;
typedef struct dnode {
int data;
struct dnode *prior;
struct dnode *next;
} dnode;

dnode *s=NULL;
dnode *p=NULL;
s=(dnode *)malloc(sizeof(dnode));
s->data=x;
s->next=s;
s->prior=s;
} else {
//先找到添加的位置
//		while(1) {
//			if(s->data>p->data) {
//				p=p->next;
//					break;
//				}
//			} else {
//				break;
//			}
//		}
//插入到p节点的前面
p->prior->next=s;
s->prior=p->prior;
s->next=p;
p->prior=s;
}
}

int x=0;
dnode *p=NULL;
printf("dlist empty\n");
return NULL;
}

printf("请输入删除的数据:\n");
scanf("%d",&x);

//找到需要删除数据的地址
while(1) {
if(p->data==x) {
break;
}
p=p->next;
printf("no this data in dlist\n");
}
}

}
p->prior->next=p->next;
p->next->prior=p->prior;

p=NULL;
} else {
free(p);
p=NULL;
}
}

printf("dlist empty\n");
return;
}

dnode *p=NULL;
while(1) {
printf("%d ",p->data);
p=p->next;
break;
}
}
printf("\n");
}
{
while(p!=tail)
{
if(p->data>p->next->data)
return false;
p=p->next;
}
return true;
}
int main() {
int n,t;
stack<int> st;
while(scanf("%d", &n)&&n) {
if(n==1){
//printf("\n");
//continue;
}
while(!st.empty()) st.pop();
for(int i=0; i<n; i++) {
cin>>t;
}
{
{
st.push(1);
}
else
{
st.push(2);
tail=tail->prior;
}
}

while(!st.empty())
{
cout<<st.top();
st.pop();
}
cout<<endl;

}
return 0;
}``````