/*Description
(线性表)设有一个正整数序列组成的有序单链表(按递增次序有序,且允许有相等的整数存在),
试编写能实现下列功能的算法(要求用最少的时间和最小的空间)
(1)确定在序列中比正整数x大的数有几个(相同的数只计算一次);
(2) 在单链表将比正整数x小的数按递减次序排列;
Input
输入长度:13
输入数据:4 5 7 7 8 10 11 15 15 16 17 20 20
输入x:10
Output
5
8 7 7 5 4
Sample Input
7
1 2 3 4 5 6 6
4
Sample Output
2
3 2 1
*/
#include<iostream>
using namespace std;
int main()
{
struct student
{
int num;
student *next;
};
student *p,*q,*s,*ss,*head=NULL;
int n,a,z,h=0;
cin>>n;
for(a=1;a<=n;a++) //the linking c++ input
{
p=new student;
if(head==NULL)
head=p;
else q->next=p;
cin>>p->num;
q=p;
}
q->next=NULL;
cin>>z; //the member of linking c++ input
p=head; //make figer and linking in memory
for(a=1;a<=n;a++)
{
if(z!=0)
{
if(p->num==z)
{
q=p;
z=0;
}
else
{
s=p;
p=p->next;
}
}
else if(z==0)
{
s=p;
p=p->next;
if(s->num==p->num)
h=h;
else h=h+1;
}
}
cout<<h<<endl;
p=head; //make new linking
while(p!=q&&h!=0)
{
if(p==head)
{
s=p->next;
ss=s->next;
head=NULL;
p->next=NULL;
s->next=p;
p=s;
}
else
{
s=ss;
ss=ss->next;
s->next=p;
p=s;
}
}
head=p;
p=head; //the member c++ output
while(p->next!=NULL)
{
p=p->next;
cout<<p->num<<" ";
}
return 0;
}