IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Tab Content
Pas d'activité récente

7 Messages visiteurs

  1. Trunks
    // swap.cpp
    #include "push_swap.h"

    void sa(t_rdlist *l_a)
    {
    int value;

    value = l_a->first->value;
    l_a->first->value = l_a->first->next->value;
    l_a->first->next->value = value;
    }

    void sb(t_rdlist *l_b)
    {
    int value;

    value = l_b->first->value;
    l_b->first->value = l_b->first->next->value;
    l_b->first->next->value = value;
    }

    void ss(t_rdlist *l_a, t_rdlist *l_b)
    {
    sa(l_a);
    sa(l_b);
    }

    // permute.cpp
    #include "push_swap.h"

    void pa(t_rdlist *l_a, t_rdlist *l_b)
    {
    t_dlist *node;

    if ((node = ft_rdlist_pop_front(l_b)))
    ft_rdlist_push_front(l_a, node);
    }

    void pb(t_rdlist *l_a, t_rdlist *l_b)
    {
    t_dlist *node;

    if ((node = ft_rdlist_pop_front(l_a)))
    ft_rdlist_push_front(l_b, node);
    }

    // rotate.cpp
  2. Trunks
    #include "push_swap.h"

    t_dlist *ft_rdlist_pop_front(t_rdlist *rdlist)
    {
    t_dlist *node;

    if ((node = rdlist->first))
    {
    // Check empty
    rdlist->first = node->next;
    rdlist->first->previous = rdlist->last;
    rdlist->last->next = rdlist->first;
    node->previous = NULL;
    node->next = NULL;
    }
    return (node);
    }

    t_dlist *ft_rdlist_pop_back(t_rdlist *rdlist)
    {
    t_dlist *node;

    if ((node = rdlist->last))
    {
    // Check empty
    rdlist->last = node->previous;
    rdlist->first->previous = rdlist->last;
    rdlist->last->next = rdlist->first;
    node->previous = NULL;
    node->next = NULL;
    }
    return (node);
    }
  3. Trunks
    void ft_rdlist_clear(t_rdlist *rdlist)
    {
    t_dlist *current;
    t_dlist *next;

    current = rdlist->first;
    while (current)
    {
    next = current->next;
    free(current);
    if (current == rdlist->last)
    break ;
    current = next;
    }
    rdlist->first = NULL;
    rdlist->last = NULL;
    }

    void ft_rdlist_display(const t_rdlist *rdlist)
    {
    const t_dlist *current;

    current = rdlist->first;
    while (current)
    {
    ft_putnbr_fd(current->value, 1);
    if (current->next)
    ft_putchar_fd(' ', 1);
    if (current == rdlist->last)
    break ;
    current = current->next;
    }
    ft_putchar_fd('\n', 1);
    }
  4. Trunks
    t_dlist *ft_rdlist_push_front_value(t_rdlist *rdlist, int value)
    {
    t_dlist *node;

    if ((node = ft_dlist_create_node(value)))
    {
    if (rdlist->first)
    {
    node->next = rdlist->first;
    node->previous = rdlist->last;
    rdlist->first->previous = node;
    rdlist->last->next = node;
    rdlist->first = node;
    }
    else
    {
    node->next = node;
    node->previous = node;
    rdlist->first = node;
    rdlist->last = node;
    }
    }
    return (node);
    }

    t_dlist *ft_rdlist_push_back_value(t_rdlist *rdlist, int value)
    {
    t_dlist *node;

    if ((node = ft_dlist_create_node(value)))
    {
    if (rdlist->first)
    {
    node->next = rdlist->first;
    node->previous = rdlist->last;
    rdlist->first->previous = node;
    rdlist->last->next = node;
    rdlist->last = node;
    }
    else
    {
    node->next = node;
    node->previous = node;
    rdlist->first = node;
    rdlist->last = node;
    }
    }
    return (node);
    }
  5. Trunks
    #include <stdlib.h>
    #include "push_swap.h"

    void ft_rdlist_init(t_rdlist *rdlist)
    {
    rdlist->first = NULL;
    rdlist->last = NULL;
    }

    t_dlist *ft_rdlist_push_front(t_rdlist *rdlist, t_dlist *node)
    {
    if (rdlist->first)
    {
    node->next = rdlist->first;
    node->previous = rdlist->last;
    rdlist->first->previous = node;
    rdlist->last->next = node;
    rdlist->first = node;
    }
    else
    {
    node->next = node;
    node->previous = node;
    rdlist->first = node;
    rdlist->last = node;
    }
    return (node);
    }

    t_dlist *ft_rdlist_push_back(t_rdlist *rdlist, t_dlist *node)
    {
    if (rdlist->first)
    {
    node->next = rdlist->first;
    node->previous = rdlist->last;
    rdlist->first->previous = node;
    rdlist->last->next = node;
    rdlist->last = node;
    }
    else
    {
    node->next = node;
    node->previous = node;
    rdlist->first = node;
    rdlist->last = node;
    }
    return (node);
    }
  6. Trunks
    #ifndef PUSH_SWAP_H
    # define PUSH_SWAP_H

    # ifndef NULL
    # define NULL 0
    # endif

    typedef struct s_dlist;

    typedef struct s_rdlist
    {
    struct s_dlist *first;
    struct s_dlist *last;
    } t_rdlist;

    typedef struct s_dlist
    {
    int value;
    struct s_dlist *previous;
    struct s_dlist *next;
    } t_dlist;

    #endif /* !PUSH_SWAP_H */

    #include <stdlib.h>
    #include "push_swap.h"

    t_dlist *ft_dlist_create_node(int value)
    {
    t_dlist *node;

    if ((node = (t_dlist *) malloc(sizeof(*node))))
    {
    node->value = value;
    node->previous = NULL;
    node->next = NULL;
    }
    return (node);
    }
  7. Trunks
    #include <stdlib.h>
    #include "push_swap.h"

    int main(int argc, char *argv[])
    {
    t_rdlist l_a;
    t_rdlist l_b;

    if (!init(argc, argv, &l_a, &l_b))
    return (clean_exit(&l_a, &l_b, EXIT_FAILURE));
    ft_rdlist_display(&l_a);
    return (clean_exit(&l_a, &l_b, EXIT_SUCCESS));
    }

    //ft_swap.cpp
    #include <stdlib.h>
    #include "push_swap.h"

    int init(int argc, char *argv[], t_rdlist *l_a, t_rdlist *l_b)
    {
    int i;

    ft_rdlist_init(l_a);
    ft_rdlist_init(l_b);
    i = 1;
    while (i < argc)
    {
    if (!ft_rdlist_push_back_value(l_a, ft_atoi(argv[i])))
    return (0);
    ++i;
    }
    return (1);
    }

    int clean_exit(t_rdlist *l_a, t_rdlist *l_b, int value)
    {
    if (value != EXIT_SUCCESS)
    ft_putstr_fd("Error\n", 2);
    ft_rdlist_clear(l_a);
    ft_rdlist_clear(l_b);
    return (value);
    }
Visualiser les messages visiteur de 1 à 7 sur 7
Informations de Trunks

Informations de base

Date de naissance
22 Mars 1983 (40)
Informations de Trunks
Sexe:
Homme
Pays:
France
Activité:
Développeur informatique

Statistiques


Messages au total
Messages au total
534
Messages par jour
0,07
Messages visiteurs
Messages au total
7
Plus récent message
24/12/2013 18h32
Informations générales
Dernière activité
26/04/2020 17h07
Date d'inscription
04/05/2004
Aucune certification n'a été indiquée. Déclarez vos certifications