Skip to content

Sort data into a stack, using a set of limited instructions, and with the fewest operations possible using sorting algorithms.

Notifications You must be signed in to change notification settings

FlorentBelotti/42_cursus_push_swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

42_cursus_push_swap---------------------------------------------------

C

Table of Contents---------------------------------------------------

Introduction---------------------------------------------------

The push_swap project is designed to test and improve your algorithmic skills by sorting data using stacks. You will implement a program that sorts a stack of integers using a defined set of operations. The goal is to achieve this with the minimum number of operations.

Mandatory Part---------------------------------------------------

Rules

The push_swap program must sort a list of integers passed as arguments using two stacks named a and b. Initially, stack a contains the integers, and stack b is empty. The program must produce the shortest sequence of operations to sort the integers in ascending order in stack a.

The allowed operations are:

  • sa: Swap the first two elements at the top of stack a.
  • sb: Swap the first two elements at the top of stack b.
  • ss: sa and sb simultaneously.
  • pa: Push the top element of stack b onto stack a.
  • pb: Push the top element of stack a onto stack b.
  • ra: Rotate stack a upwards (top element becomes the last).
  • rb: Rotate stack b upwards (top element becomes the last).
  • rr: ra and rb simultaneously.
  • rra: Reverse rotate stack a (bottom element becomes the first).
  • rrb: Reverse rotate stack b (bottom element becomes the first).
  • rrr: rra and rrb simultaneously.

Program Overview---------------------------------------------------

The push_swap program consists of several key components:

  • error_check.c: Validates the input arguments to ensure they are integers and there are no duplicates.
  • pile_operations.c: Contains the implementation of stack operations such as push, swap, rotate, and reverse rotate.
  • pile_memory_management.c: Manages the memory allocation and deallocation for the stacks.
  • pile_interchanger.c: Manages the transfer of elements between stacks a and b.
  • sort_pile.c: Implements the sorting algorithm to determine the sequence of operations needed to sort the stack.
  • tiny_sort.c: Provides optimized sorting methods for small sets of integers.
  • sort_group.c and sort_rotation.c: Implement advanced sorting strategies and rotations to minimize the number of operations.
  • push_swap_main.c: The main entry point of the program, which initializes the stacks, processes input, and invokes the sorting algorithm.

Compilation---------------------------------------------------

To compile the project, use the provided Makefile. Ensure it includes the rules all, clean, fclean, and re to manage the compilation process. The Makefile will compile the source files and generate the executable push_swap.

About

Sort data into a stack, using a set of limited instructions, and with the fewest operations possible using sorting algorithms.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published