没有合适的资源?快使用搜索试试~ 我知道了~
冒泡,直接插入,简单选择排序源程序
3星 · 超过75%的资源 需积分: 10 8 下载量 14 浏览量
2011-12-22
18:40:28
上传
评论 4
收藏 49KB DOC 举报
温馨提示
试读
3页
#include"stdio.h" #include"malloc.h" #define MAXSIZE 100 typedef int KeyType; /*关键码类型定义*/ typedef struct node { KeyType key; /*关键码定义*/ }ElemType; /*数据元素类型*/ typedef struct { ElemType elem[MAXSIZE+1]; /*elem[0]在下面排序中作为监测点*/ int length; }S_TBL; /*顺序存储的数据元素序列*/ void Print(S_TBL p); S_TBL *Creat() /*创建链表,申请存放数据的空间并给p*/ { S_TBL *p;
资源推荐
资源详情
资源评论
#include"stdio.h"
#include"malloc.h"
#define MAXSIZE 100
typedef int KeyType; /*关键码类型定义*/
typedef struct node
{
KeyType key; /*关键码定义*/
}ElemType; /*数据元素类型*/
typedef struct
{
ElemType elem[MAXSIZE+1]; /*elem[0]在下面排序中作为监测点*/
int length;
}S_TBL; /*顺序存储的数据元素序列*/
void Print(S_TBL p);
S_TBL *Creat() /*创建链表,申请存放数据的空间并给 p*/
{
S_TBL *p;
int n,i;
printf("数据元素的个数: ");
scanf("%d",&n);
p=(S_TBL *)malloc(sizeof(S_TBL));
p->length=n;
printf("请输入数据元素:");
for(i=1;i<n+1;i++)
scanf("%d",&p->elem[i].key);
return p;
}
void InsertSort(S_TBL p) /*直接插入排序*/
{
int i,j;
for(i=2;i<=p.length;i++)
if(p.elem[i].key<p.elem[i-1].key)
{
p.elem[0].key=p.elem[i].key;
for(j=i-1;p.elem[0].key<p.elem[j].key;j--)
p.elem[j+1]=p.elem[j];
p.elem[j+1]=p.elem[0];
}
Print(p);
}
void Bublesort(S_TBL p) /*冒泡排序*/
{
int i,j;
ElemType q;
资源评论
- 神速2014-01-06挺好的 还能用
zeng_liming
- 粉丝: 1
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功