0% found this document useful (0 votes)
192 views

Pascal Single Link List

This document describes procedures for implementing a linked list data structure in Pascal. It includes procedures for: 1) Displaying menus to add, delete, search, or sort data in the linked list. 2) Inserting nodes at the front or back of the linked list. 3) Deleting nodes from the front or back of the linked list. 4) Traversing the linked list to display its contents.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
192 views

Pascal Single Link List

This document describes procedures for implementing a linked list data structure in Pascal. It includes procedures for: 1) Displaying menus to add, delete, search, or sort data in the linked list. 2) Inserting nodes at the front or back of the linked list. 3) Deleting nodes from the front or back of the linked list. 4) Traversing the linked list to display its contents.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

program tugas2; uses crt; type bank = record nama : string; need : string; noan : integer; end; node

= ^data; data = record info : bank; {tipe data info} next,prev : node; end; var menu,temp,n : integer; x : bank; menu2: char; first,last :node;

procedure tampilan1; begin writeln('========================================='); writeln(' LINKED LIST '); writeln('========================================='); writeln('Pilih Menu Yang Diinginkan'); writeln('1. Memasukan/Delete Data'); writeln('2. Mencari Data(Unique)'); writeln('3. Mencari Data(non unique)'); writeln('4. Mengurutkan Data'); writeln('5. keluar'); write('pilhan anda [1-5] : ');readln(menu); {validasi menu pilihan} while (menu < 0) or (menu > 5) do begin write('salah memilih menu, Masukan angka = ');read(menu); end; end;

procedure tampilan2; begin writeln('========================================='); writeln(' LINKED LIST OPTIONS '); writeln('========================================='); writeln('Pilih Menu Yang Diinginkan'); writeln('1. Sisip Depan'); writeln('2. Sisip Belakang'); writeln('3. Hapus Depan'); writeln('4. Hapus Belakang'); writeln('5. Baca List(Traversal Pro)');

writeln('6. Penghancuran'); writeln('7. Baca List(Traversal Func)'); writeln('8. Menu Awal'); write('pilhan anda [1-8] : ');readln(menu); {validasi menu pilihan} while (menu < 0) or (menu > 8) do begin write('salah memilih menu, Masukan angka = ');read(menu); end; end;

procedure create(var first,last:node); begin first := nil; last := nil; end; procedure sisipd(var x:bank; var first,last:node); var P:node; begin repeat clrscr; writeln('========================================='); writeln(' DAFTAR ANTRI BANK '); writeln('========================================='); write('Masukan Nama = '); readln(x.nama); write('Masukan Kebutuhan = '); readln(x.need); write('Masukan Nomor Antri = '); readln(x.noan); new(P); P^.info:= x; if(first=nil) then begin P^.next:=nil; last:=P; end else begin P^.next:=first; end; first := P; write('Apa anda ingin menginput data lagi (Y/T) ?');readln(menu2); until (menu2='T') or (menu2='t'); end;

procedure sisipb(x:bank; var first,last:node); var P:node;

begin repeat clrscr; writeln('========================================='); writeln(' DAFTAR ANTRI BANK '); writeln('========================================='); write('Masukan Nama = '); readln(x.nama); write('Masukan Kebutuhan = '); readln(x.need); write('Masukan Nomor Antri = '); readln(x.noan); new(P); P^.next:=nil; P^.info:= x; if(first=nil) then begin P^.next:=nil; last:=P; end else begin last^.next:=P; end; last := P; write('Apa anda ingin menginput data lagi (Y/T) ?');readln(menu2); until (menu2='T') or (menu2='t'); end;

Procedure Df(var first,last:node); Var P : node; Begin If first <> nil then Begin P:=first; first:= first^.next; end; If first = nil then begin last := nil; Dispose(P); end; end;

Procedure Dl(var first,last:node); Var P, PrecLast : node; Begin If (first<>nil) then Begin P := last; PrecLast := first ; While (PrecLast^.next <> last) do

PrecLast := PrecLast^.next; If PrecLast^.next = first then Begin first := nil; last := nil; End Else Begin PrecLast^.next := nil; last := PrecLast; End; Dispose(P) End; End;

procedure traversal(var first:node); var i : node; begin clrscr; writeln('========================================='); writeln(' Daftar List Yang Telah Diisi '); writeln('========================================='); writeln(); i := first; while i <> nil do begin writeln(); writeln('Nama Costumer = ',i^.info.nama); writeln('Kebutuhan Costumer = ',i^.info.need); writeln('Nomor Antri Costumer = ',i^.info.noan); i := i^.next; writeln(); end; writeln; readkey(); end; function traversal2(var first:node):node; var i : node; begin clrscr; writeln('========================================='); writeln(' Daftar List Yang Telah Diisi '); writeln('========================================='); writeln(); i := first; while i <> nil do begin writeln(); writeln('Nama Costumer = ',i^.info.nama); writeln('Kebutuhan Costumer = ',i^.info.need); writeln('Nomor Antri Costumer = ',i^.info.noan); i := i^.next; writeln(); end;

writeln; traversal2:=i; readkey(); end;

Function search(var n:integer; first:node):boolean; Var Found :boolean; Begin writeln('========================================='); writeln(' Menu Pencarian '); writeln('========================================='); writeln(); write ('Masukan nomor antrian yang ingin dicari =');read(n); Found:=false; Repeat If first^.info.noan = n then Found := true Else first := first^.next Until Found or (first=nil); if found = true then begin writeln('Nama Costumer = ',first^.info.nama); writeln('Kebutuhan Costumer = ',first^.info.need); writeln('Nomor Antri Costumer = ',first^.info.noan); end; if found = false then begin writeln('Data Tidak Ditemukan'); end; Search:=Found; readkey(); End;

procedure cari(var first:node); var i : node; name : string; begin clrscr; writeln('========================================='); writeln(' Daftar List Yang Telah Diisi '); writeln('========================================='); writeln(); write('Masukan nama yang ingin dicari : '); readln(name); i := first; while (i <> nil) do begin if (first^.info.nama=name) then begin

writeln(); writeln('Nama Costumer = ',i^.info.nama); writeln('Kebutuhan Costumer = ',i^.info.need); writeln('Nomor Antri Costumer = ',i^.info.noan); writeln(); end; i := i^.next; end; writeln; readkey(); end;

procedure SortList(var temp:integer; var first,last:node); var p,min,j : node; begin p := first; while(p <> last) do begin min := p; j := p^.next; while ( j <> last) do begin if (j^.info.noan < min^.info.noan)then begin min := j; end; j := j^.next; end; temp := p^.info.noan; p^.info.noan := min^.info.noan; min^.info.noan := temp; writeln(); writeln('Nama Costumer = ',p^.info.nama); writeln('Kebutuhan Costumer = ',p^.info.need); writeln('Nomor Antri Costumer = ',p^.info.noan); writeln(); p := p^.next; end; readkey(); end;

procedure penghancuran(var first:node); var p:node;

begin p:=first; while (p<>nil)do begin first := first^.next; dispose(p); p := first; end; first:=nil; last:=nil; end;

begin repeat clrscr; tampilan1; if (menu=1) then begin repeat clrscr; tampilan2; if (menu=0) then begin create(first,last); end; if (menu=1) then begin sisipd(x,first,last); end; if (menu=2) then begin sisipb(x,first,last); end; if (menu=3) then begin df(first,last); end; if (menu=4) then begin dl(first,last); end; if (menu=5) then begin traversal(first); end; if (menu=6) then begin penghancuran(first); end;

if (menu=7) then begin traversal2(first); end; until (menu=8); end; if (menu=2) then begin clrscr; search(n,first); end; if (menu=3) then begin clrscr; cari(first); end; if (menu=4) then begin clrscr; sortlist(temp,first,last); end; until menu=5; end.

You might also like