直接插入排序(Straight Insertion Sort)的C语言实现
- 若新记录<有序表高位l.r[j],则设置哨兵
- 有序表后移,j+1=j
- 重复第2步,直至新纪录>=有序表中的j记录,则j+1就是要插入的位置

#include <stdio.h> typedef float keyType;
typedef struct{
keyType score;
char name[];
}student;
typedef struct{
int length=;
student stu[];
}sqList; void SIS(sqList &L){
for(int i=;i<L.length;i++){
if(L.stu[i].score>L.stu[i-].score){
L.stu[]=L.stu[i];//设置哨兵
int j;
for(j=i-;L.stu[].score>L.stu[j].score;j--)
L.stu[j+]=L.stu[j];//记录后移
L.stu[j+]=L.stu[];//找到位置,插入元素
}
}
} int main(){
sqList L; for(int i=;i<L.length;i++){
printf("\n请输入第%d个学生的姓名:",i);
gets(L.stu[i].name);
printf("分数:");
scanf("%f",&(L.stu[i].score));
getchar();
} SIS(L);
for(int i=;i<L.length;i++){
printf("\n学生%s 分数%f 第%d名",L.stu[i].name,L.stu[i].score,i);
}
}

直接插入排序(Straight Insertion Sort)的C语言实现的更多相关文章
- 插入排序—直接插入排序(Straight Insertion Sort)
基本思想: 将一个记录插入到已排序好的有序表中,从而得到一个新,记录数增1的有序表.即:先将序列的第1个记录看成是一个有序的子序列,然后从第2个记录逐个进行插插入到已入,直至整个序列有序为止. 要点: ...
- 直接插入排序(Straight Insertion Sort)
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- 排序之直接插入排序(Straight Insertion Sort)
一.直接插入排序(Straight Insertion Sort) 排序的过程如下:给定无需序列:(3,6,9,7,1,8,2,4) ① 3,6,9,7,1,8,2,4 (将6插入到有序序列3中) ② ...
- 直接插入排序(Straight Insertion Sort)
直接插入排序(Straight Insertion Sort)的基本操作是将一个记录插入到已经排好序的有序表中,从而得到一个新的.记录数增1的有序表. /* 对顺序表L作直接插入排序 */ void ...
- 直接插入排序(Straight Insertion Sort)
1.定义 直接插入排序(Straight Insertion Sort)的基本操作是将一个记录插入到已经排好序的有序表中,从而得到一个新的.记录数增1的有序表. 插入排序(Insertion Sort ...
- 《算法4》2.1 - 插入排序算法(Insertion Sort), Python实现
排序算法列表电梯: 选择排序算法:详见 Selection Sort 插入排序算法(Insertion Sort):非常适用于小数组和部分排序好的数组,是应用比较多的算法.详见本文 插入排序算法的语言 ...
- 【算法】插入排序(Insertion Sort)
(PS:内容参考MIT算法导论) 插入排序(Insertion Sort): 适用于数目较少的元素排序 伪代码(Pseudocode): 例子(Example): 符号(notation): 时间复杂 ...
- 【排序基础】5、插入排序法 - Insertion Sort
插入排序法 - Insertion Sort 文章目录 插入排序法 - Insertion Sort 插入排序设计思想 插入排序代码实现 操作:插入排序与选择排序的比较 简单记录-bobo老师的玩转算 ...
- 【算法】插入排序(Insertion Sort)(三)
插入排序(Insertion Sort) 插入排序(Insertion-Sort)的算法描述是一种简单直观的排序算法.它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相 ...
随机推荐
- 洛谷2344 奶牛抗议(DP+BIT+离散化)
洛谷2344 奶牛抗议 本题地址:http://www.luogu.org/problem/show?pid=2344 题目背景 Generic Cow Protests, 2011 Feb 题目描述 ...
- Square(强大的剪枝)
http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=2410 /* 题意; 给出一定数量的棍子用这 ...
- Jenkins 七: 部署到Tomcat
在build.xml定义了打包target之后,我们可以将打包生成的war文件直接部署到tomcat. 1. 建立Tomcat用户. 打开Tomcat安装路径下的 conf/tomcat-users. ...
- Linux在山Windows共享文件夹
$ sudo mount.cifs //windows-ip/shared /media/ -o user=username password=password 该命令挂载Windows在下面sha ...
- sparkSQL1.1入门之二:sparkSQL执行架构
在介绍sparkSQL之前.我们首先来看看,传统的关系型数据库是怎么执行的.当我们提交了一个非常easy的查询: SELECT a1,a2,a3 FROM tableA Where con ...
- stl_alloc.h
/* * Copyright (c) 1996-1997 * Silicon Graphics Computer Systems, Inc. * * Permission to use, copy, ...
- Android(java)学习笔记236:多媒体之加载大图片到内存(Bitmap API)
1.Bitmap (API使用) android里面的bitmap中,一个像素点需要4个byte去表示,这是因为android表示颜色是" argb ":其中 a 表示是透明度,然 ...
- josn 转php
$data = josn_decode(data,[true]); 加true转化为php数组:不加为对象,使用:$data->'字段'.
- asp.net中@page 指令的属性Inherits、Src、CodeBehind区别
在 ASP.NET 中使用代码隐藏方法来设计Web 窗体,可使页代码能够更清晰地从 HTML 内容中分离到完全单独的文件中. <%@ Page language="c#" C ...
- Python sys.path.append
python sys.path.append 对于模块和自己写的程序不在同一个目录下,可以把模块的路径通过sys.path.append(路径)添加到程序中. 在程序开头加上: import syss ...