#include<cstring>
typedef struct pan
{
int data;
struct pan *next,*prior;
} Panda;
void Input(Panda *head,int N)
{
Panda *p=head;
while(N--)
{
Panda *pnew=new Panda;
scanf("%d",&pnew->data);
p->next=pnew;
pnew->prior=p;
pnew->next=head;
head->prior=pnew;
p=pnew;
}
return ;
}
void Bubble(Panda *head,int N)
{
for(int i=0; i<N; i++)
{
bool flag=1;
Panda *p=head->next;
for(int j=0; i+j<N-1&&p->next!=head; p=p->next)
{
if(p->data>p->next->data)
{
int cub=p->data;
p->data=p->next->data;
p->next->data=cub;
flag=0;
}
}
if(flag==1) break;
}
return ;
}
void Output(Panda *head)
{
Panda *p=head->next;
while(p!=head)
{
printf("%d\n",p->data);
p=p->next;
}
return ;
}
int main()
{
Panda *head=new Panda;
head->next=head->prior=head;
int N=10;
Input(head,N);
Bubble(head,N);
Output(head);
return 0;
}
/**************************************************************
Language: C++
Result: Accepted
Time:0 ms
Memory:1028 kb
****************************************************************/