#include
#include
#include
using namespace std;
struct node
{
int x;
node *next;
node(int a){x=a;}
};
class link
{
public :
node *head;
link(int *a)
{
int n=5;
head=new node(a[0]);
node *p=head;
while(--n)
{
node *add=new node(a[n]);
p->next=add;
p=p->next;
}
}
void comfive(link & l)
{
int n=10;
int state=1;
int t;
int state2=1;
node *p=head;
node *lp=l.head;
while(p->next)
{
p=p->next;
}
while(lp)
{
node *add=new node(lp->x);
lp=lp->next;
p->next=add;
p=p->next;
}
// p->next=l.head;
p=head;
node *q=p->next;
while(n--&&state)
{p=head;q=p->next;
while(q)
{
if(p->x < q->x){ t=p->x;p->x=q->x; q->x=t;state=0;}
p=p->next;
q=q->next;
}
if(state==1)break;
state=1;
}
n=1;
p=head;
q=p->next;
/*****************/
while(n<5&&state2)
{ q=p->next;
if(p->x==q->x);
else n++;
p=p->next;
//cout<<"no five"<next->x==q->x)
q->next->next=NULL;
else q->next=NULL;
/*****************/
}
~link()
{
delete head;
}
void print()
{
node *p=head;
while(p)
{
cout<x<<" ";
p=p->next;
}cout<x) > ((l.head)->x))?head:l.head;
node *cur=head;
node *p=head->next;
node *q=l.head;
if(head->x==l.head->x)
{ head->next=l.head;cur=l.head;q=l.head->next;n--;}
// 9 7 5 3
// 8 6 4 2
while(--n)
{
if(p->x == q->x){ //n++;bug//cur->next=p;cur=cur->next; cur->next=q;cur=cur->next; }
else
{
if(p->x > q->x) { cur->next=p; p=p->next;}
else { cur->next=p; q=q->next;}
}
// cout<
分享标题:选前5名的链表问题
转载源于:http://kswsj.cn/article/igccsj.html