PFDS 11.2.2

Post on 31-May-2015

293 views 2 download

Tags:

Transcript of PFDS 11.2.2

PFDS 11.2Catenable Double-Ended

Queues~ using implicit recursive slowdown ~

@rf0444

Simple Implementationdata Cat a = Shallow (Deq a) | Deep (Deq a) (Cat (Deq a)) (Deq a)

Simple Implementation

++

Simple Implementation

snoc

cons

Simple Implementation

Simple Implementation

++( )

Simple Implementation

++( )

再帰 O(min(log n1, log n2))

using compound elementsdata Cat a = Shallow (Deq a) | Deep (Deq a) (Cat (Ele a)) (Deq a) (Cat (Ele a)) (Deq a)

using compound elementsdata Ele a = Simple (Deq a) | Compound (Deq a) (Cat (Ele a)) (Deq a)

using compound elements

++

using compound elements

using compound elements

using compound elements

snoc cons

using compound elements

using compound elements

using compound elementstail

1. f が 4 要素以上

2.a の先頭が Simple

3.a の先頭が Compound

4.a が空、b の先頭が Simple

5.a が空、b の先頭が Compound

6.a も b も空

f a m b r

using compound elementstail (1)

using compound elementstail (1)

using compound elementstail (2)

using compound elementstail (2)

using compound elementstail (2)

using compound elementstail (3)

using compound elementstail (3)

using compound elementstail (3)

using compound elementstail (3)

using compound elementstail (3)

++

using compound elementstail (3)

using compound elementstail (3)

using compound elementstail (4)

using compound elementstail (4)

using compound elementstail (4)

using compound elementstail (4)

using compound elementstail (4)

using compound elementstail (5)

using compound elementstail (5)

using compound elementstail (5)

using compound elementstail (5)

using compound elementstail (5)

using compound elementstail (5)

using compound elementstail (6)

空 空

using compound elementstail (6)

空 空

using compound elementstail (6)

*どちらかのサイズが 3 以下なら、くっつけて Shallow

using compound elementstail (6)

using compound elementstail (6)

空 空