Skip to content

Black-Hole1004/push_swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

push_swap

Writing a sorting algorithm is always a very important step in a developer’s journey. It is often the first encounter with the concept of complexity. Sorting algorithms and their complexity are part of the classic questions discussed during job interviews. It’s probably a good time to look at these concepts since you’ll have to face them at some point. The learning objectives of this project are rigor, use of C, and use of basic algorithms. Especially focusing on their complexity. Sorting values is simple. To sort them the fastest way possible is less simple. Especially because from one integers configuration to another, the most efficient sorting solution can differ.

The rules

• You have 2 stacks named a and b. • At the beginning: ◦ The stack a contains a random amount of negative and/or positive numbers which cannot be duplicated. ◦ The stack b is empty. • The goal is to sort in ascending order numbers into stack a. To do so you have the following operations at your disposal:

  1. sa (swap a): Swap the first 2 elements at the top of stack a. Do nothing if there is only one or no elements.
  2. sb (swap b): Swap the first 2 elements at the top of stack b. Do nothing if there is only one or no elements.
  3. ss : sa and sb at the same time.
  4. pa (push a): Take the first element at the top of b and put it at the top of a. Do nothing if b is empty.
  5. pb (push b): Take the first element at the top of a and put it at the top of b. Do nothing if a is empty.
  6. ra (rotate a): Shift up all elements of stack a by 1. The first element becomes the last one.
  7. rb (rotate b): Shift up all elements of stack b by 1. The first element becomes the last one.
  8. rr : ra and rb at the same time.
  9. rra (reverse rotate a): Shift down all elements of stack a by 1. The last element becomes the first one.
  10. rrb (reverse rotate b): Shift down all elements of stack b by 1. The last element becomes the first one.
  11. rrr : rra and rrb at the same time.

check out my push_swap tester here :

push_swap_tester

About

creating a sorting algorithm.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published