Presentation is loading. Please wait.

Presentation is loading. Please wait.

S T A C K Catatan Kuliah: Algoritma & Struktur Data Ari Cahyono, S.Si., M.T.

Similar presentations


Presentation on theme: "S T A C K Catatan Kuliah: Algoritma & Struktur Data Ari Cahyono, S.Si., M.T."— Presentation transcript:

1 S T A C K Catatan Kuliah: Algoritma & Struktur Data Ari Cahyono, S.Si., M.T

2 Stack = Tumpukan In = PUSH Aturan: LIFO (Last In First Out)

3 Stack = Tumpukan Out = POP Aturan: LIFO (Last In First Out)

4 Stack = Tumpukan Aturan: LIFO (Last In First Out) IN OUT TOP MaxStack =

5 Deklarasi const MaxStack = ; type TData = ; { bebas } TStack = record Entry: array[0..MaxStack-1] of TData; Top: -1..MaxStack-1; { Integer} end; Top Entry TStack TData

6 Operasi-operasi pada Stack Initialize Stack Mengosongkan Stack Push Data into Stack Memasukkan data ke dalam Stack Pop Data from Stack Mengambil data dari Stack Copy Data from Stack Menyalin isi salah satu data yang ada pada Stack tanpa mengurangi anggota Stack.

7 Initialize Stack Mengosongkan Stack procedure InitStack(var S: TStack); begin S.Top := -1 end; Top Entry TStack Variable Parameter

8 PUSH procedure Push(var S: TStack; X: TData); begin if not (S.Top = MaxStack-1) then begin Inc(S.Top); {S.Top := S.Top +1} S.Entry[S.Top] := X; end; Top Entry TStack 2+1 = 3 7 = MaxStack -1 Catatan: Jk S.Top = MaxStack – 1  Stack Penuh Not (S.Top = MaxStack-1) ~ S.Top < MaxStack-1 X

9 POP procedure Pop(var S: TStack; var X: TData); begin if not (S.Top = -1) then begin X := S.Entry[S.Top]; Dec(S.Top); {S.Top := S.Top – 1} end; Entry TStack 3-1 = 2 Catatan: Jk S.Top = -1  Stack Kosong Not (S.Top = -1) ~ S.Top > -1 3 Top Variabel X digunakan untuk menerima salinan data dari puncak Stack X

10 Copy Stack Data procedure CopyStack(var S: TStack; N: Integer; var X: TData); begin if N in [0..S.Top] then X := S.Entry[N]; end; Top Entry TStack N in [0..S.Top] setara dengan N >= 0 and N <= S.Top X Misal: N = 3

11 Terima Kasih


Download ppt "S T A C K Catatan Kuliah: Algoritma & Struktur Data Ari Cahyono, S.Si., M.T."

Similar presentations


Ads by Google