Skip to content

Sort a stack of numbers with the least amount of movements

Notifications You must be signed in to change notification settings

mjorgecruz/42_push_swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

42_push_swap

Push_swap is a project designed to test algorithmic thinking, problem-solving, and optimization skills. The goal is to sort a stack of integers using a limited set of operations, while achieving the most efficient solution in terms of the number of moves. The project consists of two main programs:

Push_swap:

This program generates a sequence of commands to sort a list of integers. The available operations include pushing elements between two stacks (push), rotating stacks (rotate), reversing stack rotations (reverse rotate), and swapping the first two elements of a stack (swap). The challenge is to use these operations optimally. The program required the implementation of a cost dependant algorithm to define the most efficient way to sort elements in a stack.

Checker:

This is a separate program that takes the list of commands outputted by push_swap and the initial list of integers to verify if the result is sorted correctly.


Push_swap emphasizes the importance of writing efficient, clean, and well-structured code. It also serves as an introduction to algorithmic optimization.


To run:

  1. Clone repository

    git clone git@github.com:mjorgecruz/42_push_swap.git
  2. Run make

    cd 42_push_swap
    make
  3. Run ./push_swap {list_of_numbers}

    ./push_swap 1 3 2 5 4

About

Sort a stack of numbers with the least amount of movements

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published