33,027
社区成员




void listmaroplayers(Node* head)
{
int m;
Node* q=head;
Node* tail=NULL;
while(true){
q = head;
for(;q->next!=tail;q=q->next)
if(q->value>q->next->value)
{
m=q->value;
q->value=q->next->value;
q->next->value=m;
}
tail = q;
if(head->next==tail)
break;
}
}
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node* creat()
{
struct node *h,*p,*q;
int i,n;
printf("输入想创建的节点个数:");
scanf("%d",&n);
h=(struct node *)malloc(sizeof(struct node));
h->data=n;
h->next=NULL;
q=h;
for(i=0;i<n;i++)
{
p=(struct node*)malloc(sizeof(struct node));
printf("input num[%d]:",i);
scanf("%d",&p->data);
p->next=NULL;
q->next=p;
q=p;
}
printf("创建的链表为:");
return h;
}
void print(struct node *head)
{
struct node *p;
p=head->next;
while(p!=NULL)
{
printf("->%d",p->data);
p=p->next;
}
printf("\n");
}
struct node* order(struct node *head)
{
struct node *h,*p,*q;
int i,chg;
h=head;
for(i=0;i<100;i++)
for(q=h->next,p=q->next ;p!=NULL;q=p,p=p->next)
if(q->data>p->data)
{
chg=q->data;
q->data=p->data;
p->data=chg;
}
printf("排序后链表为:");
return h;
}
void main()
{
struct node *head,*head1;
head=creat();
print(head);
head1=order(head);
print(head1);
}