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)
这是排序算法中最常见的排序方法,也是初学者使用最多的.有时候我们在生活中也会不自觉地用到插入排序,例如: 给手里的牌排序 这是最常见的例子之一,我们通常从纸牌的一边开始看,找到一张位置不正确的,把它拿 ...
随机推荐
- [Locked] Flatten 2D Vector
Problem Description: Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [ ...
- hdoj 1513 Palindrome【LCS+滚动数组】
Palindrome Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 谁动了我的timer?——C#的垃圾回收和调试
先来看如下的一段代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 using System; using System.Threading; publi ...
- 1002 A + B Problem II [ACM刷题]
这一段时间一直都在刷OJ,这里建一个博客合集,用以记录和分享算法学习的进程. github传送门:https://github.com/haoyuanliu/Online_Judge/tree/mas ...
- Swift中FDMB的使用(增、删、改、查)
直接上代码: import UIKit class ZWDBManager: NSObject { //前提将FMDBDatabase的头文件增加到桥接文件里 var dataBase:FMDatab ...
- cocos2dx c++ 在mac下写的中文凝视,在win32下编译时不通过
今天遇到个奇怪的问题,在mac下写的程序,加的中文凝视,编译没有问题,可是在win32下(使用的时vs2012, win7 64bit 系统)编译就总是报错 最后在中文凝视后 加一个空格,或者 换行, ...
- POJ2250:Compromise(LCS)
Description In a few months the European Currency Union will become a reality. However, to join the ...
- Android开发艺术探索》读书笔记 (5) 第5章 理解RemoteViews
第5章 理解RemoteViews 5.1 RemoteViews的应用 (1)RemoteViews表示的是一个view结构,它可以在其他进程中显示.由于它在其他进程中显示,为了能够更新它的界面,R ...
- 二分图最大匹配(匈牙利算法Dfs模板)
#include<iostream> #include<cstdio> #include<cstring> #define maxn 2020 using name ...
- Tab页签切换
js之tab页签切换效果 现在web网站,很多地都需要用到tab页签. 示例: $(document).ready(function(){ va ...