unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} type MyRec = record Name: string[8]; Age : Word; end; var RecArr: array[0..3] of MyRec; procedure TForm1.FormCreate(Sender: TObject); begin RecArr[3].Name := '李四'; RecArr[3].Age := 16; RecArr[2].Name := '张三'; RecArr[2].Age := 61; RecArr[1].Name := '钱二'; RecArr[1].Age := 24; RecArr[0].Name := '赵一'; RecArr[0].Age := 42; end; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(RecArr[0].Name); {赵一} ShowMessage(RecArr[1].Name); {钱二} ShowMessage(RecArr[2].Name); {张三} ShowMessage(RecArr[3].Name); {李四} end; end.链表与数组的异同:
1、数组中的元素在内存中是连续的; 链表不是.
2、数组的内存是一次性分配和释放的; 链表不是.
3、链表定位元素是顺藤摸瓜; 数组是一步到位, 更快.
4、链表可以方便的插入和删除元素; 用数组实现即麻烦有费时, 基本没人这样做.
5、链表拥有更多扩展的潜力!