中国石凳联盟 登录注册

C中的两种常见排序法

rj45··12 回复·343 浏览

发表回复

冒泡法:


#include stdio.h
void main()
{
int i
int j
int temp
int arr={23,90,9,25,16}


for (i=3i=0i--)
{
for (j=4j=4-ij--)
{
if (arrarr)
{
temp=arr
arr=arr
arr=temp
}
}
}
printf ("排序后为:n")
for (i=0i5i++)
{
printf ("n%d",arr
)
}
}


插入法:


#include stdio.h
void insertnum(int arrnum,int i,int j)
void main()
{
int i,j


int arr={23,90,9,25,16}


for (i=1i5i++)
{
for (j=0jij++)
{
if (arrarr
)
{
insertnum(arr,i,j)
}
}
}
printf ("排序后为:n")
for (i=0i5i++)
{
printf ("%dt",arr
)
}
}


void insertnum(int arrnum,int x,int y)
{
int temp
temp=arrnum
for (xyx--)
{
arrnum=arrnum
}
arrnum=temp
}
Being a devil is the same as being a human. We should be kind. If we are kind, we are not a devil, we are a hybrid.
点赞0 收藏
今天还听说有一个希尔排序法,我见都没见过,今天刚听说还不会
Being a devil is the same as being a human. We should be kind. If we are kind, we are not a devil, we are a hybrid.
点赞0 收藏

数据结构里就有学的.不过都是理论的东西,实践起来很头痛.至少当初把我考得要死.

主要有冒泡/堆/树/希尔/哈希等,还分稳不稳定....操蛋.头痛.
点赞0 收藏
挺多的,实用的时候掌握一两种效率高的也就行了,当然做学问另当别论
点赞0 收藏
希尔法估计不错,要研究一下
Being a devil is the same as being a human. We should be kind. If we are kind, we are not a devil, we are a hybrid.
点赞0 收藏
没说完,过一年在说
Being a devil is the same as being a human. We should be kind. If we are kind, we are not a devil, we are a hybrid.
点赞0 收藏
打错字了,你又不是不知道我经常的啦
Being a devil is the same as being a human. We should be kind. If we are kind, we are not a devil, we are a hybrid.
点赞0 收藏
那我只能回个靠
Being a devil is the same as being a human. We should be kind. If we are kind, we are not a devil, we are a hybrid.
点赞0 收藏
以下是引用rj45在2005-4-17 3:33:03的发言:打错字了,你又不是不知道我经常的啦

问题是以往即便你有错字, 但猜猜还是能猜出来什么意思, 这次完全搞不懂了
点赞0 收藏
不懂就用五笔试
Being a devil is the same as being a human. We should be kind. If we are kind, we are not a devil, we are a hybrid.
点赞0 收藏
发表回复
发表回复