Upgrade to Pro — share decks privately, control downloads, hide ads and more …

42tokyo-push_swap-data_structure

love42
February 23, 2023

 42tokyo-push_swap-data_structure

love42

February 23, 2023
Tweet

More Decks by love42

Other Decks in Programming

Transcript

  1. 3 6 4 2 5 1 a[0] a[1] a[2] a[3]

    a[4] a[5] stack A malloc ./push_swap 3 6 4 2 5 1
  2. 6 4 5 a[0] a[1] a[2] a[3] a[4] a[5] 3

    2 1 b[0] b[1] b[2] b[3] b[4] b[5] stack A stack B malloc B
  3. push 3 4 5 6 a[0] a[1] a[2] a[3] a[4]

    a[5] 2 1 b[0] b[1] b[2] b[3] b[4] b[5] stack A stack B push stack A push stack B pa
  4. 3 b 1 NULL 6 c 4 d 2 e

    5 f ./push_swap 3 6 4 2 5 1 a b c d e f malloc malloc malloc malloc malloc malloc t_list t_node head num next
  5. push 1 NULL stack A stack B 3 c 6

    NULL 4 e 2 f 5 b a b c d e head : a head : d f pa
  6. push 1 NULL stack A stack B 3 c 6

    NULL 4 e 2 a 5 b a b c d e f head : d head : f f
  7. rotate 1 d stack A stack A 3 c 6

    d 4 e 2 NULL 5 b a b c d e head : a head : d f rra 1 NULL 3 c 6 d 4 e 5 b a b c e f 2 a d
  8. NULL 3 b e 1 NULL a 6 c b

    4 d c 2 e d 5 f ./push_swap 3 6 4 2 5 1 a b c d e f malloc malloc malloc malloc malloc malloc t_list t_node head tail num next prev
  9. rotate NULL 3 c b 1 d e 6 f

    a 4 e f 2 NULL c 5 b a b c d e f d 3 c b 1 NULL e 6 f a 4 e NULL 2 a c 5 b a b c d e f stack A stack A head : a tail : d head : d tail : f rra tail -> prev