+ All Categories
Home > Software > Data Structure (Stack)

Data Structure (Stack)

Date post: 13-Jan-2017
Category:
Upload: adam-mukharil-bachtiar
View: 130 times
Download: 0 times
Share this document with a friend
32
STACK Adam M.B.
Transcript
Page 1: Data Structure (Stack)

STACK

Adam M.B.

Page 2: Data Structure (Stack)

DEFINITION

Page 3: Data Structure (Stack)

Stack

Stack is data structure whose its

elemen can be added and taken only

from last position (top).

Page 4: Data Structure (Stack)

Components of Stack• Top is a variable which refers to last

position in stack.

• Element is component which has data.

• MaxStack is variable that describes maximum number of elements in a stack.

Page 5: Data Structure (Stack)

DECLARATION

Page 6: Data Structure (Stack)

Declaration as ArrayKamus:

Const

MaxStack = value {value is integer number}

Type

NamaStack = array [1..MaxStack] of tipedata

Stack : NamaStack

Top : integer {pointer of stack}

Page 7: Data Structure (Stack)

Declaration as ListKamus:

Type

NamaPointer = ↑Stack Stack = Record

< MedanData : TipeData,

MedanSambungan : NamaPointer >

EndRecord

Top : NamaPointer {pointer of stack}

Page 8: Data Structure (Stack)

OPERATION

Page 9: Data Structure (Stack)

Operation• Initialization

• Empty Operation

• Full Operation (array)/One Node

Operation (Linked List)

• Push

• Pop

Page 10: Data Structure (Stack)

Main Operation

PUSH

STACK

Take data from element

in stack

POPAdd data to element in

stack.

Page 11: Data Structure (Stack)

Kinds of Operation

•Stack Operation in array form

•Stack Operation in Linked list form

Page 12: Data Structure (Stack)

STACK OPERATION IN ARRAY FORM

Page 13: Data Structure (Stack)

Operation that give a initial value for top pointer in stack with the following rules:• Give 0 if the first element starts

from 1• Give -1 if the first element starts

from 0

Initialization

Page 14: Data Structure (Stack)

Operation that returns true if the top pointer have 0 or -1 as its value (depend on initialization) or returns

false to the contrary.

Empty Operation

Page 15: Data Structure (Stack)

Operation that returns true if top have reached maximum array or maximum array -1 (depend on

initialization) or returns false if top is not equal to maximum array.

Full Operation

Page 16: Data Structure (Stack)

Steps in push operation:• Stack can be added when it’s not

full• Add the top pointer with 1 • Stack element, which was refered

by top pointer, is filled with new data.

Push

Page 17: Data Structure (Stack)

Push

1

2

3

4

0Top

Push(Top,Stack,8)Push(Top,Stack,3)Push(Top,Stack,5)Push(Top,Stack,1)Push(Top,Stack,7)

8

3

5

1

“Stack Penuh”

Stack

Page 18: Data Structure (Stack)

Steps in pop operation:• Stack can be pop when its

elements is not empty.• Element that have taken out from

stack is saved in a variable.• Substract the top pointer with 1.

Pop

Page 19: Data Structure (Stack)

Pop

1

2

3

4

0Top

Pop(Top,Stack,Elemen)Pop(Top,Stack,Elemen)Pop(Top,Stack,Elemen)Pop(Top,Stack,Elemen)Pop(Top,Stack,Elemen)

8

3

5

1

“Stack Kosong”

Stack 1Elemen

538

Page 20: Data Structure (Stack)

STACK OPERATION IN LINKED LIST

FORM

Page 21: Data Structure (Stack)

Prepare stack by giving null value to the top pointer in stack.

Initialization

Page 22: Data Structure (Stack)

Operation that returns true if the top

pointer isn’t null or returns false to the contrary.

Empty Operation

Page 23: Data Structure (Stack)

Operation that returns true if right connection field has null value (stack

only has one node) or returns false to the contrary.

One Node Operation

Page 24: Data Structure (Stack)

Steps of push operation in linked list

form is similar with front insertion.

Push

Page 25: Data Structure (Stack)

Push Push(Top,8)

baru 8

Top

Push(Top,3)

baru 3 8

Top

Page 26: Data Structure (Stack)

Push

Push(Top,5)

baru 3 8

Top

5

Page 27: Data Structure (Stack)

Steps of pop operation in linked list

form is similar with front deletion.

Pop

Page 28: Data Structure (Stack)

Pop Pop(Top,Elemen)

Phapus

3 8

Top

5

Elemen

Page 29: Data Structure (Stack)

Pop Pop(Top,Elemen)

Phapus

3 8

Top

Elemen

Page 30: Data Structure (Stack)

Pop Pop(Top,Elemen)

Phapus

8

Top

Elemen

Page 31: Data Structure (Stack)

Do the task 6.27 until 6.29 in page 210 at Data Structures book, seymour.

Exercise

Page 32: Data Structure (Stack)

Contact Person:Adam Mukharil Bachtiar

Informatics Engineering UNIKOMJalan Dipati Ukur Nomor. 112-114 Bandung 40132

Email: [email protected]: http://adfbipotter.wordpress.com

Copyright © Adam Mukharil Bachtiar 2012

GRACIASTHANK YOU


Recommended