level 12
qyc027
楼主
//by @qyc027
#include <stdio.h>
#include <stdlib.h>
struct node {
int num;
struct node * next;
};
int main (){
struct node * now , * head = NULL , * before;
int temnum,temp,record = 0,tempf;
puts ("请输入第一个数:");
while (scanf ("%d",& temnum) == 1)
{
now = (struct node *)malloc(sizeof (struct node));
if (head == NULL)
head = now;
else
before->next = now;
now->next = NULL;
now->num = temnum;
puts ("请输入下一个数(输入@停止):");
if (getchar() == *@*)
break;
before = now;
record ++;
}
if (head == NULL)
return 1;
else{
now = head->next;
before = head;
for (tempf = record;tempf > 0;tempf --){
now = head->next;
before = head;
while (now != NULL){
if (before->num <= now->num){
temp = before->num;
before->num = now->num;
now->num = temp;
}
else;
before = now;
now = now->next;
}
}
}
now = head;
while (now != NULL){
printf ("%d ",now->num);
now = now->next;
}
now = head;
while (now != NULL){
free (now);
now = now->next;
}
return 0;
}
2014年09月02日 01点09分
1
#include <stdio.h>
#include <stdlib.h>
struct node {
int num;
struct node * next;
};
int main (){
struct node * now , * head = NULL , * before;
int temnum,temp,record = 0,tempf;
puts ("请输入第一个数:");
while (scanf ("%d",& temnum) == 1)
{
now = (struct node *)malloc(sizeof (struct node));
if (head == NULL)
head = now;
else
before->next = now;
now->next = NULL;
now->num = temnum;
puts ("请输入下一个数(输入@停止):");
if (getchar() == *@*)
break;
before = now;
record ++;
}
if (head == NULL)
return 1;
else{
now = head->next;
before = head;
for (tempf = record;tempf > 0;tempf --){
now = head->next;
before = head;
while (now != NULL){
if (before->num <= now->num){
temp = before->num;
before->num = now->num;
now->num = temp;
}
else;
before = now;
now = now->next;
}
}
}
now = head;
while (now != NULL){
printf ("%d ",now->num);
now = now->next;
}
now = head;
while (now != NULL){
free (now);
now = now->next;
}
return 0;
}