【今天不上课】无聊写了一个链表型的冒泡排序
c新手吧
全部回复
仅看楼主
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
level 12
qyc027 楼主
@bubu高打火机
完美运行,暂时没有bug,你看怎么样?
2014年09月02日 01点09分 2
2014年09月02日 01点09分
level 12
qyc027 楼主
没有人吗[泪]
2014年09月02日 06点09分 3
level 11
[汗]链表表示看不懂。。。我下来还得学学链表。。。
2014年09月02日 09点09分 4
我以为你很牛哩。。。我初三不能再老是上了,等大吧来了就把我的小吧主先给你@00011588
2014年09月03日 04点09分
回复 qyc027 :[汗]我对于c只是个过渡。。。不准备一直搞c。。。
2014年09月03日 05点09分
回复 BuBu高打火机 :我现在主修c++和Python,看来比较困难了
2014年09月03日 05点09分
回复 qyc027 :光是c++都够你看一阵子了。[开心]
2014年09月04日 00点09分
level 12
好深奥的赶脚。[不高兴]
2014年09月02日 14点09分 5
你都水到10级了。。。
2014年09月03日 04点09分
回复 qyc027 :话说早十级了。[笑眼]
2014年09月03日 05点09分
1