Spaces:
Sleeping

File size: 680 Bytes
e7f8493
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from flask import Blueprint, render_template, request

stack_app = Blueprint("stack_app", __name__, template_folder="templates")

stack = []

@stack_app.route("/", methods=["GET"])
def index():
    return render_template("stack.html", stack=stack)

@stack_app.route("/push", methods=["POST"])
def push():
    item = request.form["item"]
    stack.append(item)
    return render_template("stack.html", stack=stack)

@stack_app.route("/pop")
def pop():
    if stack:
        stack.pop()
    return render_template("stack.html", stack=stack)

@stack_app.route("/peek")
def peek():
    top = stack[-1] if stack else None
    return render_template("stack.html", stack=stack, top=top)