Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the admin-site-enhancements domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/prntech/public_html/wp-includes/functions.php on line 6121

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the acf domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/prntech/public_html/wp-includes/functions.php on line 6121

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hide-my-wp domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/prntech/public_html/wp-includes/functions.php on line 6121

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the unlimited-elements-for-elementor domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/prntech/public_html/wp-includes/functions.php on line 6121

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wp-security-audit-log domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/prntech/public_html/wp-includes/functions.php on line 6121

Warning: Cannot modify header information - headers already sent by (output started at /home/prntech/public_html/wp-includes/functions.php:6121) in /home/prntech/public_html/wp-content/plugins/wp-force-ssl/inc/wp-force-ssl-tools.php on line 19

Warning: Cannot modify header information - headers already sent by (output started at /home/prntech/public_html/wp-includes/functions.php:6121) in /home/prntech/public_html/wp-content/plugins/wp-force-ssl/inc/wp-force-ssl-tools.php on line 23

Warning: Cannot modify header information - headers already sent by (output started at /home/prntech/public_html/wp-includes/functions.php:6121) in /home/prntech/public_html/wp-content/plugins/wp-force-ssl/inc/wp-force-ssl-tools.php on line 27

Warning: Cannot modify header information - headers already sent by (output started at /home/prntech/public_html/wp-includes/functions.php:6121) in /home/prntech/public_html/wp-content/plugins/wp-force-ssl/inc/wp-force-ssl-tools.php on line 31

Warning: Cannot modify header information - headers already sent by (output started at /home/prntech/public_html/wp-includes/functions.php:6121) in /home/prntech/public_html/wp-content/plugins/wp-force-ssl/inc/wp-force-ssl-tools.php on line 35

Warning: Cannot modify header information - headers already sent by (output started at /home/prntech/public_html/wp-includes/functions.php:6121) in /home/prntech/public_html/wp-content/plugins/wp-force-ssl/inc/wp-force-ssl-tools.php on line 39

Warning: Cannot modify header information - headers already sent by (output started at /home/prntech/public_html/wp-includes/functions.php:6121) in /home/prntech/public_html/wp-content/plugins/betterdocs-pro/includes/Admin/Analytics.php on line 25

Warning: Cannot modify header information - headers already sent by (output started at /home/prntech/public_html/wp-includes/functions.php:6121) in /home/prntech/public_html/wp-content/plugins/hide-my-wp/models/Rewrite.php on line 2905

Warning: Cannot modify header information - headers already sent by (output started at /home/prntech/public_html/wp-includes/functions.php:6121) in /home/prntech/public_html/wp-content/plugins/hide-my-wp/models/Rewrite.php on line 2908

Warning: Cannot modify header information - headers already sent by (output started at /home/prntech/public_html/wp-includes/functions.php:6121) in /home/prntech/public_html/wp-content/plugins/hide-my-wp/models/Rewrite.php on line 2909

Warning: Cannot modify header information - headers already sent by (output started at /home/prntech/public_html/wp-includes/functions.php:6121) in /home/prntech/public_html/wp-content/plugins/hide-my-wp/models/Rewrite.php on line 2910

Warning: Cannot modify header information - headers already sent by (output started at /home/prntech/public_html/wp-includes/functions.php:6121) in /home/prntech/public_html/wp-content/plugins/hide-my-wp/models/Rewrite.php on line 2911

Warning: Cannot modify header information - headers already sent by (output started at /home/prntech/public_html/wp-includes/functions.php:6121) in /home/prntech/public_html/wp-content/plugins/hide-my-wp/models/Rewrite.php on line 2919
پشته (Stack) | پراناتک

پشته (Stack)

پشته(Stack) یک ساختار داده بسیار سادست. استک، لیست با یه محدودیته. شما فقط با قسمت بالایی اون میتونین تعامل داشته باشین.

شما میتونین یه مقدار جدید به بالای پشته اضافه کنین(push)، یا مقدار موجود رو از پشته خارج کنین(pop).

میشه پشته‌ی بشقاب‌ها رو به عنوان یه تشبیه خوب معرفی کرد. شما میتونین یه بشقاب اضافه یا کم کنین. یک پشته هم به همین شکل کار میکنه.

پشته EVM، حداکثر ۱۰۲۴ عنصر جا داره. هر عنصر روی پشته، حداکثر یک مقدار ۲۵۶ بیتیه (۳۲ بایت).

MAXIMUM_STACK_SIZE = 1024

همچنین اگه سعی کنیم یه مقدار خالی رو(عنصری که وجود نداره) از پشته حذف کنیم، استثنا رخ میده.

class Stack:
    def __init__(self): self.items = []
    def __str__ (self): 
        ws = []
        for i, item in enumerate(self.items[::-1]):
            if   i == 0                : ws.append(f"{item} <first")
            elif i == len(self.items)-1: ws.append(f"{item} <last") 
            else                       : ws.append(str(item))
        return "n".join(ws)
        
    def push(self, value): 
        if len(self.items) == MAXIMUM_STACK_SIZE-1: raise Exception("Stack overflow")
        self.items.append(value)    
    
    def pop(self, n=-1):
        if len(self.items) < n: raise Exception("Stack overflow")
        del self.items[n]

یه پشته میسازیم:

stack = Stack()

سه تا عنصر بهش اضافه می کنیم:

stack.push(2)
stack.push(4)
stack.push(1)

print(stack)
1 <اولی
4
2 <آخری

یه عنصر رو ازش حذف میکنیم که در واقع 1 ه.

stack.pop()

حالا فقط دو تا مقدار توی استکمون باقی مونده. توجه کنین که ما 1 و حذف کردیم و بالاترین عنصر 4 شده.

print(stack)
4 <اولی
2 <آخری