2-路插入排序(2-way Insertion Sort)的C语言实现

#include <stdio.h>
#define LEN 6 typedef float keyType; typedef struct{
keyType score;
char name[];
}student; typedef struct{
int length=LEN;
student stu[LEN];
}sqList; void two_WayIS(sqList &L){
sqList temp;
int first=,final=;
temp.stu[first]=L.stu[];
for(int i=;i<L.length;i++){
if(L.stu[i].score>temp.stu[final].score){//插final后面
temp.stu[i]=L.stu[i];
final++;
}else if(L.stu[i].score<temp.stu[first].score){ //插first前面
if(first==) first--; //数组以1开始
first=(first-+L.length)%L.length; //first变化为1->5->4>3>2......
temp.stu[first]=L.stu[i];
}else if(L.stu[i].score<temp.stu[final].score){ //插中间
int p=(final-+L.length)%L.length;
if(p==) p--;
while(L.stu[i].score<temp.stu[p].score){
p=(p-+L.length)%L.length;
if(p==) p--;
}
final++;
int k=final;
while(k>(p+)){
temp.stu[k]=temp.stu[k-];
k=(k-+L.length)%L.length;
if(k==) k--;
}
temp.stu[p+]=L.stu[i]; }
}
} 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();
} two_WayIS(L); for(int i=;i<L.length;i++){
printf("\n学生%s 分数%f 第%d名",L.stu[i].name,L.stu[i].score,i);
}
return ;
}

2-路插入排序(2-way Insertion Sort)的C语言实现的更多相关文章
- 排序之直接插入排序(Straight Insertion Sort)
一.直接插入排序(Straight Insertion Sort) 排序的过程如下:给定无需序列:(3,6,9,7,1,8,2,4) ① 3,6,9,7,1,8,2,4 (将6插入到有序序列3中) ② ...
- 折半插入排序(Binary Insertion Sort)的C语言实现
原创文章,转载请注明来自钢铁侠Mac博客http://www.cnblogs.com/gangtiexia 折半插入排序(Binary Insertion Sort)的基本思想是将新记录插入到已经 ...
- 直接插入排序(Straight Insertion Sort)的C语言实现
原创文章,转载请注明来自钢铁侠Mac博客http://www.cnblogs.com/gangtiexia 直接插入排序(Straight Insertion Sort)的基本思想是将新记录插入到 ...
- 直接插入排序(Straight Insertion Sort)
直接插入排序(Straight Insertion Sort)的基本操作是将一个记录插入到已经排好序的有序表中,从而得到一个新的.记录数增1的有序表. /* 对顺序表L作直接插入排序 */ void ...
- 直接插入排序(Straight Insertion Sort)
1.定义 直接插入排序(Straight Insertion Sort)的基本操作是将一个记录插入到已经排好序的有序表中,从而得到一个新的.记录数增1的有序表. 插入排序(Insertion Sort ...
- [LeetCode] Insertion Sort List 链表插入排序
Sort a linked list using insertion sort. 链表的插入排序实现原理很简单,就是一个元素一个元素的从原链表中取出来,然后按顺序插入到新链表中,时间复杂度为O(n2) ...
- 经典排序算法 – 插入排序Insertion sort
经典排序算法 – 插入排序Insertion sort 插入排序就是每一步都将一个待排数据按其大小插入到已经排序的数据中的适当位置,直到全部插入完毕. 插入排序方法分直接插入排序和折半插入排序两种, ...
- [算法] 插入排序 Insertion Sort
插入排序(Insertion Sort)是一种简单直观的排序算法.它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入.插入排序在实现上,通常采用in-pla ...
- 插入排序(Insertion Sort)
这是排序算法中最常见的排序方法,也是初学者使用最多的.有时候我们在生活中也会不自觉地用到插入排序,例如: 给手里的牌排序 这是最常见的例子之一,我们通常从纸牌的一边开始看,找到一张位置不正确的,把它拿 ...
随机推荐
- 动态规划——F 最大矩阵和
Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous s ...
- Linux下p2p的聊天功能实现
Linux下p2p的聊天功能实现细节 Do one thing at a time, and do well. 今天闲着没事,写一个P2P的点对点的聊天功能的小程序,我觉得对网络编程初学者的学习很有用 ...
- mac下的改装人生——制作mac os 启动盘
我即将开始对我的mac进行彻底的改造,现在还需要的是一个mac的启动盘或者启动光盘.由于没钱买mac的安装光盘或者安装盘,只能网上下了一个镜像自己做启动盘~ 需要:装有Mac Os的电脑,至少8g的u ...
- [Locked] Smallest Rectangle Enclosing Black Pixels
An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...
- [Java] JavaMail 发送 html 格式、带附件的邮件
本案例演示发送 html 格式,可带附件的邮件发送.发送纯文本邮件的例子可参照上一篇博文JavaMail 简单案例. EmailHelper, Email 的帮助类,向帮助类提供 SMTP 服务器域名 ...
- python 解析 配置文件
资料: https://docs.python.org/3/library/configparser.html 环境 python 3.4.4 RawConfigParser方式 example.cf ...
- 启动tomcat时报classpath not found
启动tomcat时报classpath not found 原因是缺包,首先查看tomcat安装地址,然后找到webapps目录下,找到该项目,看lib下是否缺包,不能单纯的看项目下是否缺包.
- 【转】WebStorm 2016 最新版激活(activation code方式)
作者:=金刚=博客地址:http://www.cnblogs.com/woaic WebStorm 最新版本激活方式:今天下载最新版本的WebStorm,发现原来的通过license server激活 ...
- 再回首,Java温故知新(二):Java基本数据类型
Java作为一种强类型语言,意味着每一个变量都会有特定的类型,Java共有8种基本类型,其中有4种整型(byte.short.int.long).两种浮点型(float.double).1种字符型(c ...
- 深入探索C++对象模型-1
概述 在实际生产中,遇到一个复杂的类,如果能看出这个类的内存模型结构,那么以后的操作基本就没有难度的: 所以说,学会分析一个类的内存模型,是每一个C++程序员必须要会的知识. 下面,就让我们来了解C+ ...