Minggu, 19 April 2015

Linked List

Contoh Program Linked List

uses crt;
  type pointer=^typedata;
       Typedata = RECORD
       Nilai : INTEGER;
       Berikutnya : POINTER;
  end;
var list :pointer;

procedure mas_dep(var L : pointer; x : Integer);
var baru : pointer;
 begin
  new(baru);
  baru^.Nilai:=x;
  baru^.Berikutnya:= nil;
  if L= nil then L:=baru
  else
  begin
  baru^.berikutnya :=L;
  L:= baru;
  end;
 end;

procedure cetak (L:pointer);
var bantu : pointer;
 begin
  bantu:= L;
  while bantu <> nil do
  begin
  write (bantu^.Nilai:3);
  Bantu:=bantu^.Berikutnya;
   end;
  end;

 var bil, bil2 : integer;
 JB : char;
  begin
  clrscr;
  new(list);
  list:=nil;
  jb:='Y';
  writeln(' ________________________________');
  writeln('|      Program Linked List       |');
  writeln('|          Masuk Depan           |');
  writeln('|________________________________|');
  readkey;
  clrscr;
  while upcase(Jb)='Y' do
  begin
  clrscr;
   writeln(' ________________________________');
   writeln('| Masukkan bilangan :            |');
   writeln('|________________________________|');
   gotoxy(23,2);readln(bil);
   mas_dep(list,bil);
   writeln;
   writeln('| Lagi [Y/T]  :                  |');
   writeln('|________________________________|');
   gotoxy(17,4);readln(Jb);
   end;
   writeln('|________________________________|');
   writeln('|                                |');
   writeln('|________________________________|');
   gotoxy(3,6);cetak(list);
   writeln;
   readln;
   end.









0 komentar:

Posting Komentar

sealkazzsoftware.blogspot.com resepkuekeringku.com