Latihan Senarai Uji

Membangkitkan Bilangan Acak Menggunakan Matlab

Tambah dan tampil

unit unit1;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls;

//senarai berantai

type simpul=^data;

data =record

info:string;

next:simpul;

end;

//akhir deklarasi senarai berantai

type

Tform1=class(TForm)

ListBox1: TListBox;

Button1: TButton;

Button2: TButton;

Procedure Button1Click(sender:TObject);

procedure tambah_blk(var awal,akhir:simpul;elemen:string);

procedure bacamaju(awal,akhir:simpul);

procedure Button2Click(Sender: TObject);

private

{private declarations}

public

{public deklarations}

end;

var

Form1: TForm1;

elemen:string;

awal,akhir,baru:simpul;

implementation

{$R *.DFM}

procedure TForm1.tambah_blk(var awal,akhir:simpul;elemen:string);

var baru:simpul;

begin

new(baru);baru^.info:=elemen;

if awal=nil then

awal:=baru

else

akhir^.next:=baru;

akhir:=baru;

akhir^.next:=nil

end;

procedure TForm1.Button1Click(Sender:TObject);

begin

elemen:=inputbox(”,”,”);

tambah_blk(awal,akhir,elemen);

end;

procedure tform1.bacamaju(awal,akhir:simpul);

var bantu:simpul;

begin

bantu:=awal;

repeat

Listbox1.items.add(bantu^.info);

bantu:=bantu^.next ;

until bantu=nil;

End;

procedure Tform1.Button2Click(Sender: TObject);

begin

listbox1.clear;

bacamaju(awal,akhir);

end;

end.

begin

procedure TForm1.Button1Click(Sender:TObject);

begin

elemen:=inputbox(”,”,”);

tambah_blk(awal,akhir,elemen);

end;

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

procedure tform1.bacamaju(awal,akhir:simpul);

var bantu:simpul;

begin

bantu:=awal;

repeat

Listbox1.items.add(bantu^.info);

bantu:=bantu^.next ;

until bantu=nil;

End;

procedure Tform1.Button2Click(Sender: TObject);

begin

listbox1.clear;

bacamaju(awal,akhir);

end;

procedure TForm1.ListBox1Click(Sender: TObject);

begin

procedure Tform1.Button2Click(Sender: TObject);

begin

listbox1.clear;

bacamaju(awal,akhir);

end;

end.

end;

end.


Tambah, Tampil dan hapus

unit unit1;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls;

//senarai berantai

type simpul=^data;

data =record

info:string;

next:simpul;

end;

//akhir deklarasi senarai berantai

type

Tform1=class(TForm)

ListBox1: TListBox;

Button1: TButton;

Button2: TButton;

Procedure Button1Click(sender:TObject);

procedure tambah_blk(var awal,akhir:simpul;elemen:string);

procedure bacamaju(awal,akhir:simpul);

procedure Button2Click(Sender: TObject);

procedure hapus(var awal,akhir:simpul;elemen:string);

procedure Button3Click(Sender: TObject);

private

{private declarations}

public

{public deklarations}

end;

var

Form1: TForm1;

elemen:string;

awal,akhir,baru,hapus:simpul;

implementation

{$R *.DFM}

procedure TForm1.tambah_blk(var awal,akhir:simpul;elemen:string);

var baru:simpul;

begin

new(baru);baru^.info:=elemen;

if awal=nil then

awal:=baru

else

akhir^.next:=baru;

akhir:=baru;

akhir^.next:=nil

end;

procedure TForm1.Button1Click(Sender:TObject);

begin

elemen:=inputbox(”,”,”);

tambah_blk(awal,akhir,elemen);

end;

procedure tform1.bacamaju(awal,akhir:simpul);

var bantu:simpul;

begin

bantu:=awal;

repeat

Listbox1.items.add(bantu^.info);

bantu:=bantu^.next ;

until bantu=nil;

end;

procedure Tform1.Button2Click(Sender: TObject);

begin

listbox1.clear;

bacamaju(awal,akhir);

end;

procedure Tform1.hapus (var awal,akhir:simpul;elemen:string);

var bantu,hapus:simpul;

begin

if awal=nil then

showmessage(‘senarai kosong’)

else if awal^.info=elemen then

begin

hapus:=awal;

awal:=hapus^.next;

dispose (hapus);

end;

end;

procedure Tform1.Button3Click(Sender: TObject);

begin

elemen:=inputbox(”,”,”);

hapus(awal,akhir,elemen);

end;

end.

begin

procedure TForm1.Button1Click(Sender:TObject);

begin

elemen:=inputbox(”,”,”);

tambah_blk(awal,akhir,elemen);

end;

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

procedure tform1.bacamaju(awal,akhir:simpul);

var bantu:simpul;

begin

bantu:=awal;

repeat

Listbox1.items.add(bantu^.info);

bantu:=bantu^.next ;

until bantu=nil;

End;

procedure Tform1.Button2Click(Sender: TObject);

begin

listbox1.clear;

bacamaju(awal,akhir);

end;

procedure TForm1.ListBox1Click(Sender: TObject);

begin

procedure Tform1.Button2Click(Sender: TObject);

begin

listbox1.clear;

bacamaju(awal,akhir);

end;

end.

end;

end.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s


%d blogger menyukai ini: