blob: 1951da5209e93ae688bc76d8f1c3339a40dcbee8 (
plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
sort_stack
=========
Description
----------
Brief overview: the program takes in a list of integer arguments and sort them.
I put this program together to learn:
- how to choose an algorithm
- how to implement an algorithm
- how to optimize an algorithm
- how to use linked list
About linked lists: I understand that linked lists is not optimal for this use since elements are not contigious. It would expensive to use linked lists to solve such problem.
This program uses:
- my own interpretation of the "turk algorithm" when there are more than 5 elements to sort
- the "mini-turk" algorithm when there are 4 or 5 elements
- hard-coded algorithms when there are 2 or 3 elements
Improvement:
- I could further optimize the choice of element to move by taking both costs, of stack A and stack B, into consideration.
## Instructions
Build the program:
make
Run the program:
bin/push_swap [arguments]
Delete objects files:
make clean
Delete objects files and program:
make fclean
Recompile:
make re
## Resources
- https://medium.com/@ayogun/push-swap-c1f5d2d41e97
- Harvard CS50 lecture on data structures
|