מבני נתונים ואלגוריתמים - מחברת קורס/מבני נתונים/מחסניות: הבדלים בין גרסאות בדף

תוכן שנמחק תוכן שנוסף
Atavory (שיחה | תרומות)
Atavory (שיחה | תרומות)
שורה 100:
# An array-based stack.
Stack
# An array storing the values.
1 Values
# The current used size.
2 size
 
 
# Creates a stack.
Make-Stack()
1 stk = Stack()
 
# Note we're using the global variable max-size.
2 stk.Values = Make-Array(max-size)
3 stk.size = 0
 
4 return stk
 
 
# Pushes (inserts) a value (v) to a stack (stk).
Push(stk, v)
1 stk.Values[++stk.size] = v
 
 
שורה 125:
# (that has not yet been Pop()ed).
Pop(stk)
1 return stk.Values[stk.size--]
 
 
שורה 131:
# (that has not yet been Pop()ed).
Top(stk)
1 return stk.Values[stk.size]
 
 
# Returns the number of values inside a stack (stk).
Size(stk)
1 return stk.size</source>
 
 
===ניתוח===