-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
27 lines (22 loc) · 767 Bytes
/
Copy pathapp.py
File metadata and controls
27 lines (22 loc) · 767 Bytes
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 Flask, render_template, request
import random
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/result', methods=['POST'])
def result():
unsorted_list = request.form.get('unsorted_list')
unsorted_list = [int(i) for i in unsorted_list.split()]
sorted_list = quick_sort(unsorted_list)
return render_template('result.html', sorted_list=sorted_list)
def quick_sort(arr):
if len(arr) <= 1:
return arr
pivot = random.choice(arr)
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quick_sort(left) + middle + quick_sort(right)
if __name__ == '__main__':
app.run(debug=True)