Push Swap

Project develop for 42Cursus

Linkedin
GitHub code size in bytes Number of lines of code

96% [OK]


Description

This project involves sorting data on a stack, with a limited set of instructions, and the smallest number of moves. To make this happen, is needed to manipulate various sorting algorithms and choose the most appropriate solution(s) for optimized data sorting.

Keywords

  • Sorting algorithms
  • Battery concept and handling elements
  • Algorithm implementation

Skills

  • Unix
  • Rigor
  • Imperative programming
  • Algorithms & AI

How it Work

Small sort

This algorithm run when we have ten o fewer arguments, it is kind of a selection sort with some optimization like a swap_a before locate the lowest number in stack a, the we push it to stack b, once the stack a is already sorted we send back the number from stack b to a in order.

Long sort

Here lies the core algorithm in this project and i affectionately call as montain sort. It work with ten or more arguments and still pretty similiar from the small sort, but insted locating the smallest number, we iterate the stack and push any number lesser than the factor_to_push.

This strategy is important becase just selecting the small number is very inefficient, so, we do a pre-sort selecting from the factor_to_push, and them selecting the highest number in stack b and send back to a.

The ideia of this algorithm came from this medium where he uses chunks of values and push them in order and i adjust this chunk to be movable.


Contact:

Linkedin