| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 752 人关注过本帖
标题:[开源]明天考试,今天来几个程序
只看楼主 加入收藏
zhangzujin
Rank: 1
等 级:新手上路
帖 子:276
专家分:0
注 册:2005-5-9
收藏
 问题点数:0 回复次数:6 
[开源]明天考试,今天来几个程序

//SelectSort
#include<stdio.h>

void SelectSort(int test[],int n)
{
int i,j,small;
int tmp;

for(i=0;i<n-1;i++)
{
small=i;
for(j=i+1;j<n;j++)
if(test[j]<test[small])
small=j;
if(small!=i)
{
tmp=test[i];
test[i]=test[small];
test[small]=tmp;
}
}
}

int main( )
{
int n,test[100];
int i;

scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&test[i]);
SelectSort(test,n);
for(i=0;i<n;i++)
printf("%d ",test[i]);
printf("\n");

return 0;
}


//QuickSort
#include<stdio.h>

void QuickSort(int test[],int low,int high)
{
int i,j;
int tmp;

i=low;
j=high;
tmp=test[low];

while(i<j)
{

while(i<j && tmp<=test[j])
j--;
if(i<j)
{
test[i]=test[j];
i++;
}

while(i<j && tmp>test[i])
i++;
if(i<j)
{
test[j]=test[i];
j--;
}
}

test[i]=tmp;

if(i-1>low)
QuickSort(test,low,i-1);
if(high>j+1)
QuickSort(test,j+1,high);
}

int main( )
{
int test[100],n;
int i;

scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&test[i]);
QuickSort(test,0,n-1);
for(i=0;i<n;i++)
printf("%d ",test[i]);
printf("\n");
return 0;
}


//InsertSort
#include<stdio.h>

void InsertSort(int test[],int n)
{
int i,j;
int tmp;

for(i=0;i<n-1;i++)
{
tmp=test[i+1];
j=i;
while(j>=0 && test[j]>tmp)
{
test[j+1]=test[j];
j--;
}
test[j+1]=tmp;
}
}

int main( )
{
int test[100],n;
int i;

scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&test[i]);
InsertSort(test,n);
for(i=0;i<n;i++)
printf("%d ",test[i]);
printf("\n");
return 0;
}

//BubbleSort
#include<stdio.h>

void BubbleSort(int test[],int n)
{
int i,j,flag=1;
int tmp;

for(i=1;i<n && flag==1;i++)
{
flag=0;
for(j=0;j<n-i;j++)
if(test[j]>test[j+1])
{
flag=1;
tmp=test[j];
test[j]=test[j+1];
test[j+1]=tmp;
}
}
}

int main( )
{
int test[100],n;
int i;

scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&test[i]);
BubbleSort(test,n);
for(i=0;i<n;i++)
printf("%d ",test[i]);
printf("\n");
return 0;
}




搜索更多相关主题的帖子: int test 考试 开源 
2005-12-15 23:07
盖茨他爹
Rank: 6Rank: 6
等 级:贵宾
威 望:28
帖 子:5255
专家分:0
注 册:2005-5-3
收藏
得分:0 
什么程序?
2005-12-15 23:15
xinlingwuyu
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2005-12-7
收藏
得分:0 
~~~~~~han
2005-12-16 08:30
spp509
Rank: 1
等 级:新手上路
威 望:1
帖 子:98
专家分:0
注 册:2005-11-23
收藏
得分:0 

不解……


一听就懂,一看就会,一做就错……
2005-12-18 22:35
ghy2001
Rank: 1
等 级:新手上路
威 望:1
帖 子:87
专家分:0
注 册:2005-10-30
收藏
得分:0 
看起来累,最好来个目的先。

2005-12-19 11:12
沉默的羔羊1013
Rank: 1
等 级:新手上路
帖 子:72
专家分:0
注 册:2005-12-10
收藏
得分:0 

怎麽没写heapsort,shellsort和inordersort

2005-12-19 17:24
本人已死
Rank: 1
等 级:新手上路
威 望:1
帖 子:183
专家分:0
注 册:2005-9-20
收藏
得分:0 
几种排序嘛!

爸爸告诉我:女人喜欢有钱的男人;妈妈告诉我:女人喜欢有貌的男人。我翻翻钱包,又照照镜子,然后我哭了
2005-12-19 17:26
快速回复:[开源]明天考试,今天来几个程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017955 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved