Push_swap is a project where we have to leave data in order using two stacks and allowed operations
include
- The include filepush_swap.h
;library
- Thelibftprintf.a
inft_printf
;list
- The list functions;rules
- The rules to manipulate stakcssrc
- source code;obj
- object files.Makefile
- Makefile to compilepush_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.
I used libftprintf to make the project. This lib is already an update of libft.
I used the linked-list data structure to make the stacks. For that we have some functions to manipulate lists.
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.
- Brief: allocate space for a new node, where
-
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
.
- Brief: clean the list, use
-
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 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 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;
TODO
TODO