StringList 自定义快速排序
unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end; TMyRec = record
x: Integer;
y: Integer;
z: Integer;
end;
PMyRec = ^TMyRec; var
Form1: TForm1; implementation {$R *.dfm}
//function StringListCompareStrings(List: TStringList; Index1, Index2: Integer): Integer; function SortMethod(List: TStringList; Index1, Index2: Integer): Integer;
begin
if PMyRec(List.Objects[Index1])^.x > PMyRec(List.Objects[Index2])^.x then
Result := -
else
if PMyRec(List.Objects[Index1])^.x = PMyRec(List.Objects[Index2])^.x then
Result :=
else
Result := ;
end; procedure TForm1.Button1Click(Sender: TObject);
var
strList: TStringList;
mRec1, mRec2, mRec3: TMyRec;
pRec1, pRec2, pRec3: PMyRec;
begin
FillChar(mRec1, SizeOf(TMyRec), );
FillChar(mRec2, SizeOf(TMyRec), );
FillChar(mRec3, SizeOf(TMyRec), ); pRec1 := @mRec1;
pRec2 := @mRec2;
pRec3 := @mRec3; with mRec1 do
begin
x := ;
y := ;
z := ;
end; with mRec2 do
begin
x := ;
y := ;
z := ;
end; with mRec3 do
begin
x := ;
y := ;
z := ;
end; strList := TStringList.Create; strList.AddObject(IntToStr(pRec1^.x), TObject(pRec2));
strList.AddObject(IntToStr(pRec1^.x), TObject(pRec1));
strList.AddObject(IntToStr(pRec1^.x), TObject(pRec3)); ShowMessage( IntToStr( PMyRec(strList.Objects[])^.x ) //
+ IntToStr( PMyRec(strList.Objects[])^.x ) //
+ IntToStr( PMyRec(strList.Objects[])^.x ) //
); strList.CustomSort(SortMethod); ShowMessage( IntToStr( PMyRec(strList.Objects[])^.x ) //
+ IntToStr( PMyRec(strList.Objects[])^.x ) //
+ IntToStr( PMyRec(strList.Objects[])^.x ) //
); strList.Free; end; end.
unit Unit1;
interface
uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;
type  TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  end;
    TMyRec = record    x: Integer;    y: Integer;    z: Integer;  end;  PMyRec = ^TMyRec;
var  Form1: TForm1;
implementation
{$R *.dfm}//function StringListCompareStrings(List: TStringList; Index1, Index2: Integer): Integer;
function SortMethod(List: TStringList; Index1, Index2: Integer): Integer;begin  if PMyRec(List.Objects[Index1])^.x > PMyRec(List.Objects[Index2])^.x then    Result := -1  else  if PMyRec(List.Objects[Index1])^.x = PMyRec(List.Objects[Index2])^.x then    Result := 0  else    Result := 1;end;
procedure TForm1.Button1Click(Sender: TObject);var  strList: TStringList;  mRec1, mRec2, mRec3: TMyRec;  pRec1, pRec2, pRec3: PMyRec;begin  FillChar(mRec1, SizeOf(TMyRec), 0);  FillChar(mRec2, SizeOf(TMyRec), 0);  FillChar(mRec3, SizeOf(TMyRec), 0);
  pRec1 := @mRec1;  pRec2 := @mRec2;  pRec3 := @mRec3;
  with mRec1 do  begin    x := 1;    y := 2;    z := 3;  end;
  with mRec2 do  begin    x := 3;    y := 2;    z := 3;  end;
  with mRec3 do  begin    x := 5;    y := 2;    z := 3;  end;
  strList := TStringList.Create;
  strList.AddObject(IntToStr(pRec1^.x), TObject(pRec2));       strList.AddObject(IntToStr(pRec1^.x), TObject(pRec1));       strList.AddObject(IntToStr(pRec1^.x), TObject(pRec3));
  ShowMessage( IntToStr(   PMyRec(strList.Objects[0])^.x )       //3  + IntToStr(   PMyRec(strList.Objects[1])^.x )                  //1  + IntToStr(   PMyRec(strList.Objects[2])^.x )                  //5  );
  strList.CustomSort(SortMethod);
  ShowMessage( IntToStr(   PMyRec(strList.Objects[0])^.x )       //5  + IntToStr(   PMyRec(strList.Objects[1])^.x )                  //3  + IntToStr(   PMyRec(strList.Objects[2])^.x )                  //1  );
  strList.Free;
end;
end.
StringList 自定义快速排序的更多相关文章
- Swift学习笔记(5)--数组
		
数组的下标从0开始计数,相关方法属性涉及到下标时也从0开始计数 1.定义: //1.可变数组 var cityArray = ["Portland","San Franc ...
 - Java8 新特性(一)- Lambda 表达式
		
2014年3月18日发布了JavaSE 8 不追求技术的新,追求技术的稳定 本质:Lambda 表达式是一个匿名函数 作用:简化代码,增强代码的表达力 Lambda 语法格式 // 格式1:无参无返回 ...
 - Java集合框架实现自定义排序
		
Java集合框架针对不同的数据结构提供了多种排序的方法,虽然很多时候我们可以自己实现排序,比如数组等,但是灵活的使用JDK提供的排序方法,可以提高开发效率,而且通常JDK的实现要比自己造的轮子性能更优 ...
 - Effective Java 第三版—— 87. 考虑使用自定义序列化形式
		
Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...
 - 基本的排序算法C++实现(插入排序,选择排序,冒泡排序,归并排序,快速排序,最大堆排序,希尔排序)
		
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/8529525.html特别不喜欢那些随便转载别人的原创文章又不给 ...
 - 快排 - 快速排序算法 (Chinar出品 简单易懂)
		
Quicksort 快排的简单讲解 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...
 - Hadoop mapreduce自定义排序WritableComparable
		
本文发表于本人博客. 今天继续写练习题,上次对分区稍微理解了一下,那根据那个步骤分区.排序.分组.规约来的话,今天应该是要写个排序有关的例子了,那好现在就开始! 说到排序我们可以查看下hadoop源码 ...
 - 算法分析中最常用的几种排序算法(插入排序、希尔排序、冒泡排序、选择排序、快速排序,归并排序)C 语言版
		
每次开始动手写算法,都是先把插入排序,冒泡排序写一遍,十次有九次是重复的,所以这次下定决心,将所有常规的排序算法写了一遍,以便日后熟悉. 以下代码总用一个main函数和一个自定义的CommonFunc ...
 - c# 自定义排序类(冒泡、选择、插入、希尔、快速、归并、堆排序等)
		
using System; using System.Text; namespace HuaTong.General.Utility { /// <summary> /// 自定义排序类 ...
 
随机推荐
- C/C++中的隐式类型转换
			
代码: #include <iostream> #include <cstdio> using namespace std; int main(int argc,char* a ...
 - Qt Creator的配置
			
说明:一直想入手QT,看了相关的教程也有一段时间了,但苦于安装QT编辑器一直没有成功,今天手痒痒,于是又来捣鼓一阵子,成功了,特记录下来,方便日后查阅: 环境:win7 x64 + QT Creat ...
 - MyISAM 存储引擎
			
在MYSQL 5.1 以及之前的版本,MyISAM 是默认的存储引擎.MyISAM 提供了大量的特性,包括全文索引,压缩,空间函数(gis)等,但是MyISAM不支持事务和行级锁,而且有一个毫无疑问的 ...
 - jdk,j2ee,j2se,j2me的概念区别
			
jdk,j2ee,j2se,j2me的概念区别1.JDK是Java development toolkit,相当于是Java的库函数,是编译,运行java程序的工具包.J2EE是Java 2 ente ...
 - C#代码计时
			
using System.Diagnostics; Stopwatch sw = new Stopwatch(); sw.Start(); //todo code ....... sw.Stop(); ...
 - iPhone 和Android应用,特殊的链接:打电话,短信,email;
			
http://ice-k.iteye.com/blog/1426526 下面的这篇文章主要是说,网页中的链接如何写,可以激活电话的功能. 例如,页面中展示的是一个电话号码,当用户在手机浏览器里面点击这 ...
 - DJANTO之FORM
			
文档很仔细,但熟悉要慢慢来~~ from django.shortcuts import render from contact.forms import ContactForm from djang ...
 - linux下ifconfig, DNS以及route配置
			
转载:http://blog.csdn.net/wangjingfei/article/details/5283632/ 熟悉使用ifconfig 会非常方便. ifconfig eth0 新ip 然 ...
 - 匹配“is outside location”
			
<pre name="code" class="html">is outside location 怎么匹配? . 匹配除换行外的所有单个字符,通常 ...
 - Uva 1342 - That Nice Euler Circuit
			
Little Joey invented a scrabble machine that he called Euler, after the great mathematician. In his ...