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

Contoh Program Pointer . Deklarasi Program .

This document contains the declarations and procedures for a program that implements a first-in first-out (FIFO) queue using pointers. It declares a record type for the queue nodes, and pointer variables for the head, tail, and current node. Procedures are defined for creating the queue, inserting nodes, checking the pointer positions, determining if the queue is empty or full, navigating between nodes, retrieving a node's data, updating a node, and deleting nodes from the head, tail, or current position.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Contoh Program Pointer . Deklarasi Program .

This document contains the declarations and procedures for a program that implements a first-in first-out (FIFO) queue using pointers. It declares a record type for the queue nodes, and pointer variables for the head, tail, and current node. Procedures are defined for creating the queue, inserting nodes, checking the pointer positions, determining if the queue is empty or full, navigating between nodes, retrieving a node's data, updating a node, and deleting nodes from the head, tail, or current position.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CONTOH PROGRAM POINTER. DEKLARASI PROGRAM..

program fifo; uses crt; Const=4; Type Point = ^RecPoint; Recpoint = Record nama : string; umur : integer; Next : Point; End; Var Head, Tail, Now : Point; n:String; u,pilih:integer; MEMBUAT POINTER BARU Procedure Create; Begin Head:=nil; Tail:=nil; End; MENAMBAH DATA Procedure INSERT(elemen1:string;elemen2:integer); Var Now:Point; Begin New(Now); If head = nil then Head:=now else Tail^.next:=now; Tail:=Now; Tail^.next:=nil; Now^.nama:=elemen1; Now^.umur:=elemen2; End; MENGECEK POSISI HEAD, TAIL DAN NOW Procedure Cekpointer; begin Writeln

('nama now ',now^.nama); Writeln ('umur now ',now^.umur); writeln('nama head ',head^.nama); writeln('umur head ',head^.umur); writeln('nama tail ',tail^.nama); writeln('umur tail ',tail^.umur); readln; End; PENGECEKAN Function Empty : Boolean; Begin If head = nil then Empty:= true else empty:= false; end; Function Full : Boolean; Begin If head = max then Full:= true else Full:= false; end; MEMINDAH NOW KE HEAD Procedure Find_First; Begin Now:= head; End; MEMINDAH NOW KE DATA SESUDAHNYA Procedure Find_Next; Begin If Now^.next <> nil then Now:= Now^.next; End;

MENYIMPAB DATA NOW KE TEMP Procedure Retrieve; Begin n:= Now^.nama; u:= now^.umur; End;

MENGUBAH DATA NOW Procedure Update(elemen1: string; elemen2:integer ); Begin Now^.nama:=elemen1; now^.umur:=elemen2; End; MENGHAPUS NOW Procedure DeleteNow; Var x : point; Begin If now<>head then Begin x:=head; while x^.next<>now do x:=x^.next; x^.next:=now^.next; end else head:= head^.next; dispose(Now); Now:= head; End; MENGHAPUS HEAD Procedure DeleteHead; Begin If head<>nil then Begin Now:=head; Head:=Head^.next; Dispose(Now); Now:=Head; End; End; MENGHAPUS SEMUA Procedure Clear; Begin While head <> nil do Begin Now:=head; Head:=head^.next; Dispose(Now); End;

End.

You might also like