Skip to content

lamorim42/push_swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

push_swap

Push_swap is a project where we have to leave data in order using two stacks and allowed operations

How to navagate in this repository

  • include - The include file push_swap.h;
  • library - The libftprintf.a in ft_printf;
  • list - The list functions;
  • rules - The rules to manipulate stakcs
  • src - source code;
  • obj - object files.
  • Makefile - Makefile to compile push_swap;

How I implemented push_swap

To implement the stack structure I used linked-list as data structure. For that I build functions to manipulate the list and I used these functions to build the functions that manipulate the stack according to the project rules.

The library

I used libftprintf to make the project. This lib is already an update of libft.

Linked-list

I used the linked-list data structure to make the stacks. For that we have some functions to manipulate lists.

My list

My list has the int nbr as content and a pointer to the address of the next list element or NULL if it's the last element.

typedef struct s_lst {
	int				nbr;
	struct s_lst	*next;
}					t_lst;
  • t_lst *ft_new_elem(int i)

    • Brief: allocate space for a new node, where i is the content of the node.
    • Param: int i the content to the new node.
    • Return: a pointer to the new node.
  • void ft_delone(t_lst **head)

    • Brief: delete one element of the list, the first element.
    • Param: t_lst **head the address of the first element of the list.
    • Return: void.
  • void ft_clean_lst(t_lst **head)

    • Brief: clean the list, use free() to free used memory spaces.
    • Param: t_lst **head the address of the first element of the list.
    • Return: void.
  • t_lst *ft_last_lst(t_lst *head)

    • Brief: finds and return the last element of the list.
    • Param: t_lst *head a pointer to the first element of the list.
    • Return: a pointer to the last element of the list.

Stack

Stack is a linear abstract data type where elements are stacked and follow some rules for their manipulation. In this projects we have some rules we can use see rules. We use two stack a and b to organize the data.

My stack

My stack has a pointer to a list t_lst *lst, the length of the stack unsigned int len and the name of the stack char stk.

typedef struct s_stack {
	char			stk;
	t_lst			*lst;
	unsigned int	len;
}					t_stack;

The rules

TODO

Source code

TODO

TODO

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published