Upcoming SlideShare
×

# Taocp 2.3.5

446 views
389 views

Published on

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
446
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
1
0
Likes
0
Embeds 0
No embeds

No notes for slide
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• ### Taocp 2.3.5

2. 2. 0 a e b c d f g h(a:(b,c,d),e:(f,g,:(h)))
4. 4. A=(b,c,d) LIST=(A,a,(A,A)) b we might expectA=(c,d) ways to representthe same basic within As , ,These are many variations on List structures themea computer memory. there are usuallyaccording to which binary trees are used to represent general forests of trees: 8ay, is used to point to the next element of a List, and another LIST 3 -> bone field ‘field DLINI may be used to point to the first element of a sub-List. By a naturalextension of the memory representation described in Section 2.3.2, we wouldrepresent the List (5) as follows: b (atom) c e - - g (6) - -
5. 5. a b (atom) c - - 9 (7) - - - -
6. 6. Memory &raight linkage Circular linkagc Doublc linkagc ……location …… INFO DLINK RLINK INFO DLINK L… m RLINK INFO h [ o om RLINK …… om (t b m ’6V W b o mw c e A m c t O% Om m FU ( mm { h ” O mm O m m (8) -f -f -f m m I m l m O% g A g l % g l % om -d m -d Lm a -d h m J l % m A o% { 0% m A ka m h 1m m - ’m h I m h mm om mm h ( m I % J A 0m w m { m l % 3 JHere “LLINK" is used for a pointe1 to the left in a doubly linked 1epresentation.
7. 7. MIX a) 1 S T REF RLINK b)2 S T LLINK RLINK INFOs( ) :t( ) : t=0 ,t=1 t>1REF :L,RLINK :INFO : .( , , ..)
8. 8. !!
9. 9. (reference counter) ( ) ( )( ?) (garbage collection)
10. 10. 1 2( ) 0
11. 11. A NODE(1),NODE(2),...,NODE(M) mA1. ( ) 1K=1 //K
13. 13. A3.K=K1if(k<=M) A2else
14. 14. A1 mK mK K1 m K K1 m K K1 m
15. 15. BSTACK[1],.....B1.T STACK[1].....,STACK[T]
16. 16. B2./ T / STACK TOP ,if(T=0) end
17. 17. B3.//stack pop, KK = STACK[T]T=T-1
19. 19. B v m v m 9 5 v m7 7 3 3 v m1 1 1 1 1 v m
20. 20. ....
21. 21. CHSTACK[0],....STACK[H-1] X T = (T+1)%H STACK[T] = XT=B B = (B+1)%H K1 = min(K1,STACK[B])
22. 22. C1.T = H-1 //TOPB = H-1 //BOTTOMK1 = M + 1 // ( % push)
23. 23. C2.if(T==B) C5
24. 24. C3//stack popK = STACK[T]T = (T-1)%H
26. 26. C5if( K1 > M ) // T=B B = (B+1)%H end K1 = min(K1,STACK[B])else if(NODE(K1) == || NODE(K1) != ) K1 = K1 + 1 C5 if (NODE(K1) == ) K = K1 K = K1 + 1 C4
27. 27. C v m 9 5 v m v m7 7 3 3 v m v m1 1 1 1 6 v m
29. 29. D1.//TOPTOP = NULL Pif(S(P) == 0) S(P)=1 REF(P) = TOP // TOP TOP = P
30. 30. D2.if(TOP == NULL) // end
31. 31. D3//TOP popP = TOPTOP = REF(P)
32. 32. D4.P = RLINK(P)if(P == NULL || T(P) == 0)// D2else S(P) = 1 if(T(P) > 1) // S(REF(P)) = 1 else Q = REF(P) if(Q != NULL && S(Q) == 0) S(Q) = 1 REF(Q) = TOP TOP = Q D4
35. 35. E1.T=NULL // T 2 NULL TOP PP = P0 // P0
36. 36. E2.MARK(P) = 1 //
37. 37. E3.if(ATOM(P) == 1) // 0 E6
38. 38. E4.Q = ALINK(P)if (Q != NULL && MARK(Q) == 0) ATOM(P) = 1 ALINK(P) = T T=P p=Q E2
39. 39. E5Q = BLINK(P)if(Q != NULL && MARK(Q) == 0) BLINK(P) = T T=P P=Q E2
40. 40. E6if(T == NULL) endelse Q=T if(ATOM(Q) == 1) if(ATOM(Q) == 0) ATOM(Q) = 0 T = BLINK(Q) T = ALINK(Q) BLINK(Q) = P ALINK(Q) = P P=Q P=Q E5 E6