diff --git a/README.md b/README.md
index a8d764f..3af015f 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,30 @@
-# Books
+# Algorithm in Python
-this Repo contains solutions to different sorting algorithms written in python
+This project contains various common algorithms implemented in Python for learning purposes. The algorithms are organized into different categories:
+
+## Table of Content
+| Category | Algorithm |
+|------------------|----------------------------------------------------------------------------------------|
+| Array | [Circular Counter](https://github.com/DSC-Unilag/Algorithms/blob/master/array/circular_counter.py)
[Flatten](https://github.com/DSC-Unilag/Algorithms/blob/master/array/flatten.py)
[Garage](https://github.com/DSC-Unilag/Algorithms/blob/master/array/garage.py)
[Longest Non Repeat](https://github.com/DSC-Unilag/Algorithms/blob/master/array/longest_non_repeat.py)
[Merge Intervals](https://github.com/DSC-Unilag/Algorithms/blob/master/array/merge_intervals.py)
[Missing Ranges](https://github.com/DSC-Unilag/Algorithms/blob/master/array/missing_ranges.py)
[Plus One](https://github.com/DSC-Unilag/Algorithms/blob/master/array/plus_one.py)
[Rotate Array](https://github.com/DSC-Unilag/Algorithms/blob/master/array/rotate_array.py)
[Summary Ranges](https://github.com/DSC-Unilag/Algorithms/blob/master/array/summary_ranges.py)
[Three Sum](https://github.com/DSC-Unilag/Algorithms/blob/master/array/three_sum.py)
[Two Sum](https://github.com/DSC-Unilag/Algorithms/blob/master/array/two_sum.py)
|
+| Backtrack | [Anagram](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/anagram.py)
[Array Sum Combinations](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/array_sum_combinations.py)
[Combination Sum](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/combination_sum.py)
[Expression Add Operators](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/expression_add_operators.py)
[Factor Combinations](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/factor_combinations.py)
[General Solution.Md](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/general_solution.md)
[Generate Abbreviations](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/generate_abbreviations.py)
[Generate Parenthesis](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/generate_parenthesis.py)
[Letter Combination](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/letter_combination.py)
[Palindrome Partitioning](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/palindrome_partitioning.py)
[Pattern Match](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/pattern_match.py)
[Permute](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/permute.py)
[Permute Unique](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/permute_unique.py)
[Subsets](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/subsets.py)
[Subsets Unique](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/subsets_unique.py)
[Word Search](https://github.com/DSC-Unilag/Algorithms/blob/master/backtrack/word_search.py)
|
+| BFS | [Shortest Distance From All Buildings](https://github.com/DSC-Unilag/Algorithms/blob/master/bfs/shortest_distance_from_all_buildings.py)
[Word Ladder](https://github.com/DSC-Unilag/Algorithms/blob/master/bfs/word_ladder.py)
|
+| Bit | [Add Without Operator](https://github.com/DSC-Unilag/Algorithms/blob/master/bit/add_without_operator.py)
[Bytes Int Conversion](https://github.com/DSC-Unilag/Algorithms/blob/master/bit/bytes_int_conversion.py)
[Count Ones](https://github.com/DSC-Unilag/Algorithms/blob/master/bit/count_ones.py)
[Find Missing Number](https://github.com/DSC-Unilag/Algorithms/blob/master/bit/find_missing_number.py)
[Power Of Two](https://github.com/DSC-Unilag/Algorithms/blob/master/bit/power_of_two.py)
[Reverse Bits](https://github.com/DSC-Unilag/Algorithms/blob/master/bit/reverse_bits.py)
[Single Number](https://github.com/DSC-Unilag/Algorithms/blob/master/bit/single_number.py)
[Single Number2](https://github.com/DSC-Unilag/Algorithms/blob/master/bit/single_number2.py)
[Subsets](https://github.com/DSC-Unilag/Algorithms/blob/master/bit/subsets.py)
|
+| Calculator | [Math Parser](https://github.com/DSC-Unilag/Algorithms/blob/master/calculator/math_parser.py)
|
+| Design | [Lrucache.Md](https://github.com/DSC-Unilag/Algorithms/blob/master/design/LRUcache.md)
[Alarm System.Md](https://github.com/DSC-Unilag/Algorithms/blob/master/design/alarm_system.md)
[All O One Ds.Md](https://github.com/DSC-Unilag/Algorithms/blob/master/design/all_o_one_ds.md)
[Calculator.Md](https://github.com/DSC-Unilag/Algorithms/blob/master/design/calculator.md)
[Excel Table.Md](https://github.com/DSC-Unilag/Algorithms/blob/master/design/excel_table.md)
[Nearby Drivers.Md](https://github.com/DSC-Unilag/Algorithms/blob/master/design/nearby_drivers.md)
[Ride Sharing.Md](https://github.com/DSC-Unilag/Algorithms/blob/master/design/ride_sharing.md)
[Task Runner.Md](https://github.com/DSC-Unilag/Algorithms/blob/master/design/task_runner.md)
[Twitter Feeds.Md](https://github.com/DSC-Unilag/Algorithms/blob/master/design/twitter_feeds.md)
|
+| DFS | [All Factors](https://github.com/DSC-Unilag/Algorithms/blob/master/dfs/all_factors.py)
[Count Islands](https://github.com/DSC-Unilag/Algorithms/blob/master/dfs/count_islands.py)
[Pacific Atlantic](https://github.com/DSC-Unilag/Algorithms/blob/master/dfs/pacific_atlantic.py)
[Sudoku Solver](https://github.com/DSC-Unilag/Algorithms/blob/master/dfs/sudoku_solver.py)
[Walls And Gates](https://github.com/DSC-Unilag/Algorithms/blob/master/dfs/walls_and_gates.py)
|
+| DP | [Buy Sell Stock](https://github.com/DSC-Unilag/Algorithms/blob/master/dp/buy_sell_stock.py)
[Climbing Stairs](https://github.com/DSC-Unilag/Algorithms/blob/master/dp/climbing_stairs.py)
[Combination Sum](https://github.com/DSC-Unilag/Algorithms/blob/master/dp/combination_sum.py)
[House Robber](https://github.com/DSC-Unilag/Algorithms/blob/master/dp/house_robber.py)
[Knapsack](https://github.com/DSC-Unilag/Algorithms/blob/master/dp/knapsack.py)
[Longest Increasing](https://github.com/DSC-Unilag/Algorithms/blob/master/dp/longest_increasing.py)
[Max Product Subarray](https://github.com/DSC-Unilag/Algorithms/blob/master/dp/max_product_subarray.py)
[Max Subarray](https://github.com/DSC-Unilag/Algorithms/blob/master/dp/max_subarray.py)
[Num Decodings](https://github.com/DSC-Unilag/Algorithms/blob/master/dp/num_decodings.py)
[Regex Matching](https://github.com/DSC-Unilag/Algorithms/blob/master/dp/regex_matching.py)
[Word Break](https://github.com/DSC-Unilag/Algorithms/blob/master/dp/word_break.py)
|
+| Graph | [Clone Graph](https://github.com/DSC-Unilag/Algorithms/blob/master/graph/clone_graph.py)
[Cycle Detection](https://github.com/DSC-Unilag/Algorithms/blob/master/graph/cycle_detection.py)
[Find Path](https://github.com/DSC-Unilag/Algorithms/blob/master/graph/find_path.py)
[Graph](https://github.com/DSC-Unilag/Algorithms/blob/master/graph/graph.py)
[Traversal](https://github.com/DSC-Unilag/Algorithms/blob/master/graph/traversal.py)
|
+| Heap | [Merge Sorted K Lists](https://github.com/DSC-Unilag/Algorithms/blob/master/heap/merge_sorted_k_lists.py)
[Skyline](https://github.com/DSC-Unilag/Algorithms/blob/master/heap/skyline.py)
[Sliding Window Max](https://github.com/DSC-Unilag/Algorithms/blob/master/heap/sliding_window_max.py)
|
+| Linked List | [Add Two Numbers](https://github.com/DSC-Unilag/Algorithms/blob/master/linkedlist/add_two_numbers.py)
[Copy Random Pointer](https://github.com/DSC-Unilag/Algorithms/blob/master/linkedlist/copy_random_pointer.py)
[Delete Node](https://github.com/DSC-Unilag/Algorithms/blob/master/linkedlist/delete_node.py)
[First Cyclic Node](https://github.com/DSC-Unilag/Algorithms/blob/master/linkedlist/first_cyclic_node.py)
[Is Cyclic](https://github.com/DSC-Unilag/Algorithms/blob/master/linkedlist/is_cyclic.py)
[Is Palindrome](https://github.com/DSC-Unilag/Algorithms/blob/master/linkedlist/is_palindrome.py)
[Kth To Last](https://github.com/DSC-Unilag/Algorithms/blob/master/linkedlist/kth_to_last.py)
[Linkedlist](https://github.com/DSC-Unilag/Algorithms/blob/master/linkedlist/linkedlist.py)
[Remove Duplicates](https://github.com/DSC-Unilag/Algorithms/blob/master/linkedlist/remove_duplicates.py)
[Reverse](https://github.com/DSC-Unilag/Algorithms/blob/master/linkedlist/reverse.py)
[Rotate List](https://github.com/DSC-Unilag/Algorithms/blob/master/linkedlist/rotate_list.py)
[Swap In Pairs](https://github.com/DSC-Unilag/Algorithms/blob/master/linkedlist/swap_in_pairs.py)
|
+| Map | [Hashtable](https://github.com/DSC-Unilag/Algorithms/blob/master/map/hashtable.py)
[Longest Common Subsequence](https://github.com/DSC-Unilag/Algorithms/blob/master/map/longest_common_subsequence.py)
[Randomized Set](https://github.com/DSC-Unilag/Algorithms/blob/master/map/randomized_set.py)
[Valid Sudoku](https://github.com/DSC-Unilag/Algorithms/blob/master/map/valid_sudoku.py)
|
+| Math | [Extended Gcd](https://github.com/DSC-Unilag/Algorithms/blob/master/math/extended_gcd.py)
[Gcd](https://github.com/DSC-Unilag/Algorithms/blob/master/math/gcd.py)
[Generate Strobogrammtic](https://github.com/DSC-Unilag/Algorithms/blob/master/math/generate_strobogrammtic.py)
[Is Strobogrammatic](https://github.com/DSC-Unilag/Algorithms/blob/master/math/is_strobogrammatic.py)
[Nth Digit](https://github.com/DSC-Unilag/Algorithms/blob/master/math/nth_digit.py)
[Prime Test](https://github.com/DSC-Unilag/Algorithms/blob/master/math/prime_test.py)
[Primes Sieve Of Eratosthenes](https://github.com/DSC-Unilag/Algorithms/blob/master/math/primes_sieve_of_eratosthenes.py)
[Pythagoras](https://github.com/DSC-Unilag/Algorithms/blob/master/math/pythagoras.py)
[Rabin Miller](https://github.com/DSC-Unilag/Algorithms/blob/master/math/rabin_miller.py)
[Rsa](https://github.com/DSC-Unilag/Algorithms/blob/master/math/rsa.py)
[Sqrt Precision Factor](https://github.com/DSC-Unilag/Algorithms/blob/master/math/sqrt_precision_factor.py)
|
+| Matrix | [Bomb Enemy](https://github.com/DSC-Unilag/Algorithms/blob/master/matrix/bomb_enemy.py)
[Count Paths](https://github.com/DSC-Unilag/Algorithms/blob/master/matrix/count_paths.py)
[Matrix Rotation.Txt](https://github.com/DSC-Unilag/Algorithms/blob/master/matrix/matrix_rotation.txt)
[Rotate Image](https://github.com/DSC-Unilag/Algorithms/blob/master/matrix/rotate_image.py)
[Search In Sorted Matrix](https://github.com/DSC-Unilag/Algorithms/blob/master/matrix/search_in_sorted_matrix.py)
[Sparse Dot Vector](https://github.com/DSC-Unilag/Algorithms/blob/master/matrix/sparse_dot_vector.py)
[Sparse Mul](https://github.com/DSC-Unilag/Algorithms/blob/master/matrix/sparse_mul.py)
[Spiral Traversal](https://github.com/DSC-Unilag/Algorithms/blob/master/matrix/spiral_traversal.py)
|
+| Queue | [ Init ](https://github.com/DSC-Unilag/Algorithms/blob/master/queue/__init__.py)
[Max Sliding Window](https://github.com/DSC-Unilag/Algorithms/blob/master/queue/max_sliding_window.py)
[Moving Average](https://github.com/DSC-Unilag/Algorithms/blob/master/queue/moving_average.py)
[Queue](https://github.com/DSC-Unilag/Algorithms/blob/master/queue/queue.py)
[Reconstruct Queue](https://github.com/DSC-Unilag/Algorithms/blob/master/queue/reconstruct_queue.py)
[Zigzagiterator](https://github.com/DSC-Unilag/Algorithms/blob/master/queue/zigzagiterator.py)
|
+| Search | [Binary Search](https://github.com/DSC-Unilag/Algorithms/blob/master/search/binary_search.py)
[First Occurance](https://github.com/DSC-Unilag/Algorithms/blob/master/search/first_occurance.py)
[Last Occurance](https://github.com/DSC-Unilag/Algorithms/blob/master/search/last_occurance.py)
|
+| Set | [Randomized Set](https://github.com/DSC-Unilag/Algorithms/blob/master/set/randomized_set.py)
|
+| Sort | [Bubble Sort](https://github.com/DSC-Unilag/Algorithms/blob/master/sort/bubble_sort.py)
[Counting Sort](https://github.com/DSC-Unilag/Algorithms/blob/master/sort/counting_sort.py)
[Heap Sort](https://github.com/DSC-Unilag/Algorithms/blob/master/sort/heap_sort.py)
[Insertion Sort](https://github.com/DSC-Unilag/Algorithms/blob/master/sort/insertion_sort.py)
[Meeting Rooms](https://github.com/DSC-Unilag/Algorithms/blob/master/sort/meeting_rooms.py)
[Merge Sort](https://github.com/DSC-Unilag/Algorithms/blob/master/sort/merge_sort.py)
[Quick Sort](https://github.com/DSC-Unilag/Algorithms/blob/master/sort/quick_sort.py)
[Selection Sort](https://github.com/DSC-Unilag/Algorithms/blob/master/sort/selection_sort.py)
[Sort Colors](https://github.com/DSC-Unilag/Algorithms/blob/master/sort/sort_colors.py)
[Topsort](https://github.com/DSC-Unilag/Algorithms/blob/master/sort/topsort.py)
[Wiggle Sort](https://github.com/DSC-Unilag/Algorithms/blob/master/sort/wiggle_sort.py)
|
+| Stack | [ Init ](https://github.com/DSC-Unilag/Algorithms/blob/master/stack/__init__.py)
[Longest Abs Path](https://github.com/DSC-Unilag/Algorithms/blob/master/stack/longest_abs_path.py)
[Simplify Path](https://github.com/DSC-Unilag/Algorithms/blob/master/stack/simplify_path.py)
[Stack](https://github.com/DSC-Unilag/Algorithms/blob/master/stack/stack.py)
[Valid Parenthesis](https://github.com/DSC-Unilag/Algorithms/blob/master/stack/valid_parenthesis.py)
|
+| String | [Add Binary](https://github.com/DSC-Unilag/Algorithms/blob/master/string/add_binary.py)
[Breaking Bad](https://github.com/DSC-Unilag/Algorithms/blob/master/string/breaking_bad.py)
[Decode String](https://github.com/DSC-Unilag/Algorithms/blob/master/string/decode_string.py)
[Encode Decode](https://github.com/DSC-Unilag/Algorithms/blob/master/string/encode_decode.py)
[Group Anagrams](https://github.com/DSC-Unilag/Algorithms/blob/master/string/group_anagrams.py)
[Int To Roman](https://github.com/DSC-Unilag/Algorithms/blob/master/string/int_to_roman.py)
[Is Palindrome](https://github.com/DSC-Unilag/Algorithms/blob/master/string/is_palindrome.py)
[License Number](https://github.com/DSC-Unilag/Algorithms/blob/master/string/license_number.py)
[Make Sentence](https://github.com/DSC-Unilag/Algorithms/blob/master/string/make_sentence.py)
[Multiply Strings](https://github.com/DSC-Unilag/Algorithms/blob/master/string/multiply_strings.py)
[One Edit Distance](https://github.com/DSC-Unilag/Algorithms/blob/master/string/one_edit_distance.py)
[Rabin Karp](https://github.com/DSC-Unilag/Algorithms/blob/master/string/rabin_karp.py)
[Reverse String](https://github.com/DSC-Unilag/Algorithms/blob/master/string/reverse_string.py)
[Reverse Vowel](https://github.com/DSC-Unilag/Algorithms/blob/master/string/reverse_vowel.py)
[Reverse Words](https://github.com/DSC-Unilag/Algorithms/blob/master/string/reverse_words.py)
[Roman To Int](https://github.com/DSC-Unilag/Algorithms/blob/master/string/roman_to_int.py)
[Word Squares](https://github.com/DSC-Unilag/Algorithms/blob/master/string/word_squares.py)
|
+| TMP | [Temporary.Md](https://github.com/DSC-Unilag/Algorithms/blob/master/tmp/temporary.md)
[Tree.Md](https://github.com/DSC-Unilag/Algorithms/blob/master/tree.md)
|
+| Tree | [**Segment Tree Folder**](https://github.com/DSC-Unilag/Algorithms/tree/master/tree/Segment_Tree)
[Binary Tree Paths](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/binary_tree_paths.py)
[Bintree2List](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/bintree2list.py)
[**Bst Folder**](https://github.com/DSC-Unilag/Algorithms/tree/master/tree/bst)
[Deepest Left](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/deepest_left.py)
[Invert Tree](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/invert_tree.py)
[Is Balanced](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/is_balanced.py)
[Is Subtree](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/is_subtree.py)
[Is Symmetric](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/is_symmetric.py)
[Longest Consecutive](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/longest_consecutive.py)
[Lowest Common Ancestor](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/lowest_common_ancestor.py)
[Max Height](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/max_height.py)
[Max Path Sum](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/max_path_sum.py)
[Min Height](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/min_height.py)
[Path Sum](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/path_sum.py)
[Path Sum2](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/path_sum2.py)
[Pretty Print](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/pretty_print.py)
[Same Tree](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/same_tree.py)
[**Traversal Folder**](https://github.com/DSC-Unilag/Algorithms/tree/master/tree/traversal)
[Tree](https://github.com/DSC-Unilag/Algorithms/blob/master/tree/tree.py)
[**Trie**](https://github.com/DSC-Unilag/Algorithms/tree/master/tree/trie)
|
+| Union Find | [Count Islands](https://github.com/DSC-Unilag/Algorithms/blob/master/union-find/count_islands.py)
diff --git a/design/alarm_system.md b/design/alarm_system.md
index 8c3fdaa..7674e92 100644
--- a/design/alarm_system.md
+++ b/design/alarm_system.md
@@ -1 +1,54 @@
-Design an alarm system for a driverless car
+# Design an alarm system for a driverless car
+
+An alarm system for a driverless car would involve several different components, including sensors to detect potential hazards, software to process sensor data and make decisions based on it, and actuators to take action in response to those decisions. Here's one possible design for such a system using Python:
+
+- Sensors: The car would be equipped with various sensors such as cameras, lidar, radar, and ultrasonic sensors to detect potential hazards in the car's environment, such as other vehicles, pedestrians, and obstacles.
+
+- Data Processing: The sensor data would be processed by software running on the car's onboard computer. This software would use algorithms such as object detection and tracking to identify and locate potential hazards, and would make decisions about how to respond based on the car's current state and the detected hazards.
+
+- Actuators: The car would have actuators such as brakes, steering, and accelerators to take action in response to the decisions made by the software. For example, if the car detects a potential collision with another vehicle, it would apply the brakes to slow down or stop.
+
+- Alarm: The car would be equipped with an alarm system that sounds an alarm in case of any emergency or if the system detects any potential hazards. The alarm system would be connected to the software running on the car's onboard computer, and would be triggered in response to the decisions made by the software.
+
+- Communication: The car would be equipped with communication systems such as cellular, wifi and satellite to be able to communicate with the outside world. The car would send a message to the owner or the nearest service center in case of an emergency or if the system detects any potential hazards.
+
+``` python
+class AlarmSystem:
+ def __init__(self):
+ self.sensors = {
+ 'camera': CameraSensor(),
+ 'lidar': LidarSensor(),
+ 'radar': RadarSensor(),
+ 'ultrasonic': UltrasonicSensor()
+ }
+ self.data_processor = DataProcessor()
+ self.actuators = {
+ 'brakes': BrakeActuator(),
+ 'steering': SteeringActuator(),
+ 'accelerator': AcceleratorActuator()
+ }
+ self.alarm = Alarm()
+ self.communication = Communication()
+
+ def detect_and_respond_to_hazard(self):
+ sensor_data = self.gather_sensor_data()
+ hazards = self.data_processor.detect_hazards(sensor_data)
+ if hazards:
+ self.alarm.sound()
+ self.communication.send_emergency_message()
+ self.actuators['brakes'].apply()
+ self.actuators['steering'].steer_away_from_hazard()
+ self.actuators['accelerator'].reduce_speed()
+
+ def gather_sensor_data(self):
+ sensor_data = {}
+ for sensor_name, sensor in self.sensors.items():
+ sensor_data[sensor_name] = sensor.get_data()
+ return sensor_data
+
+ def stop_emergency_response(self):
+ self.alarm.stop()
+ self.actuators['brakes'].release()
+ self.actuators['steering'].reset()
+ self.actuators['accelerator'].reset()
+```
diff --git a/design/calculator.md b/design/calculator.md
index 463d2db..344a905 100644
--- a/design/calculator.md
+++ b/design/calculator.md
@@ -66,3 +66,61 @@ boolean isDigit(char ch) {
}
}
```
+### Python
+``` python
+import collections
+
+def is_digit(ch):
+ return ch >= '0' and ch <= '9'
+
+def calc(op2, op1, ch):
+ if ch == '-':
+ return op1 - op2
+ elif ch == '+':
+ return op1 + op2
+ elif ch == '/':
+ return op1 / op2
+ elif ch == '*':
+ return op1 * op2
+ else:
+ return 0
+
+def higher_priority(op1, op2):
+ if op1 == '*' or op1 == '/':
+ return True
+ if op2 == '+' or op2 == '-':
+ return True
+ return False
+
+def simple_calculator(exp):
+ st = collections.deque()
+ op = collections.deque()
+ digit = 0
+ has_digit = False
+ for i in range(len(exp)):
+ if is_digit(exp[i]):
+ has_digit = True
+ digit = digit * 10 + int(exp[i])
+ else:
+ if has_digit:
+ has_digit = False
+ st.append(digit)
+ digit = 0
+ if exp[i] == '(':
+ op.append('(')
+ elif exp[i] == ')':
+ while op[-1] != '(':
+ st.append(calc(st.pop(), st.pop(), op.pop()))
+ op.pop()
+ else:
+ while op and op[-1] != '(' and higher_priority(op[-1], exp[i]):
+ st.append(calc(st.pop(), st.pop(), op.pop()))
+ op.append(exp[i])
+ if has_digit:
+ st.append(digit)
+ while op:
+ st.append(calc(st.pop(), st.pop(), op.pop()))
+ return st[-1]
+
+```
+
diff --git a/design/task_runner.md b/design/task_runner.md
index b6aa3b3..89b7476 100644
--- a/design/task_runner.md
+++ b/design/task_runner.md
@@ -50,3 +50,34 @@ r.push(exampleTask) // run
r.push(exampleTask) // wait
r.run();
```
+### Python
+``` python
+import time
+
+def example_task(done):
+ time.sleep(2)
+ done()
+
+class Runner:
+ def __init__(self, num):
+ self.max_num = num
+ self.counter = 0
+ self.queue = []
+
+ def push(self, callback_fn):
+ self.queue.append(callback_fn)
+
+ def run(self):
+ if self.queue and self.counter < self.max_num:
+ self.counter += 1
+ task = self.queue.pop(0)
+ done = lambda: self.counter -= 1 and self.run() and print(f'number at this moment: {self.counter}')
+ task(done)
+
+r = Runner(3)
+r.push(example_task) # run
+r.push(example_task) # run
+r.push(example_task) # run
+r.push(example_task) # wait
+r.run()
+```
\ No newline at end of file
diff --git a/queue/__pycache__/__init__.cpython-39.pyc b/queue/__pycache__/__init__.cpython-39.pyc
new file mode 100644
index 0000000..8235779
Binary files /dev/null and b/queue/__pycache__/__init__.cpython-39.pyc differ
diff --git a/queue/__pycache__/queue.cpython-39.pyc b/queue/__pycache__/queue.cpython-39.pyc
new file mode 100644
index 0000000..9e7d0ed
Binary files /dev/null and b/queue/__pycache__/queue.cpython-39.pyc differ