???? (Linked List) - PowerPoint PPT Presentation

1 / 95
About This Presentation
Title:

???? (Linked List)

Description:

(Linked List) : (Pointer) (linked list) ... – PowerPoint PPT presentation

Number of Views:166
Avg rating:3.0/5.0
Slides: 96
Provided by: wuwu
Category:
Tags: doubly | link | linked | list

less

Transcript and Presenter's Notes

Title: ???? (Linked List)


1
  • ???? (Linked List)
  • ?????(Pointer)

???????
2
??????
  • ????(linked list)??????????,??????????????????????
    ????,?????????????????????
  • ?????????????????,??????
  • ??????????(?????),???????????????????

?????? ????????
????? ????????? ????????
???? ????????????? ????????????
????? ?????????? ?????????
???????? ?????????,???????????? ?????????,????????????
3
??(Node)
  • ?? (Node)???????????
  • ?? (Node) ?????????????
  • ?????????
  • ???????????????????

4
Node??????
  • ????
  • struct node
  • int number
  • struct node llink
  • Node ???
  • head (struct node ) malloc (sizeof(struct
    node))

5
Node??????(?)
  • ????
  • struct node
  • string name
  • string address
  • int phone
  • struct node llink
  • Node ???
  • head (struct node ) malloc (sizeof(struct
    node))

6
Example
  • ???????????(node)????????,?????(data)????(next)?,?
    ??????
  • Struct node
  • int data
  • struct node next
  • ???????a, b, c, d, x???????
  • head??????????
  • tail??????????

tail
head
a b c d x
7
??????
  • ???? (Linked List) ??????????,???????????????????
  • ????,????????????? (Data) ??? (Link)?
  • ?????????
  • ??????????????????????,?????????????
  • ??,????????,???????????
  • ?????????-??????,????????????,???????????
  • ???????????????????
  • ???????????,???????????????,?????????????
  • ???????????????,????????????????????,?????????

8
??????(?)
  1. ??(a)??,pHead(??????????),??4????
  2. ??????????,???????????????????
  3. ?????????????null??,????????
  4. ?????????null??,????????????,??(b) ???

9
????????
  • ?????????????????? ??,??????????????
  • ???????,?????????? ???
  • ???????????????,????????,?????????
  • ????????????????? (Head Pointer)
    ?????,pHead?? head??,?link??????????

10
??????
  • ???
  • ??????(single linked list)
  • ????(circular linked list)
  • ??????(doubly linked list)

11
????????
  1. ??????????,????(insert)???(delete)????(node)?????
    ??
  2. ???????a,b,d,e????,??c?????,?????????
  3. ????d,e????,???c????????,??????????????,?????????
    ????
  4. ??????????????(linked list)?

12
??????(?)
  1. ????????????????????,????????(pointer)?????????
  2. ???????????(node)????????,?????(data)????(next)?
    ,?????????struct node ??,?????

13
??????(?)
  • ??? Aa, b, c, d,???????
  • head?????????,????????data??????????,?????????
    ?????

14
??????(????????)
  • ????????
  • ????x?????????,?????

(1) x(struct node) malloc(sizeof(struct
node)) (2) x-gtnexthead-gtnext
15
??????(????????)
  • (3)head-gtnextx

16
??????(????????)
  • ????????
  • ????x????????,?????

(1)x(struct node ) malloc(sizeof(struct
node))
17
??????(????????)
  • (2)x-gtnextNULL

18
??????(????????)
  • ???????????????,?????????
  • ??????????

19
??????(????????)
  • (3)p-gtnextx

20
??????(??????????????)
  • ??????????,?data??????????

21
??????(??????????????)
  • ?????ptr?data????75,????????????????????????,??
    ??75????80?70??,??????????????

22
??????(??????????????)
  • ??prev?current???????,prev????current????

23
??????(??????????????)
  • ?????????ptr??????prev???
  • ptr-gtnextcurrent / ? /
  • prev-gtnextptr / ? /

?
?
24
??????(??????)
  • ????????
  • ???????????
  • phead-gtnext
  • head-gtnextp-gtnext
  • free(p)

25
??????(??????)
  • (1) phead-gtnext

26
??????(??????)
  • (2) head-gtnextp-gtnext

27
??????(??????)
  • (3)free(p)
  • ??free(p)???p?????

28
??????(?????????)
  • ????????
  • ?????????????????????,????

29
??????(?????????)
30
??????(?????????)
31
??????(?????????)
  • ??????????????????current?prev,???????????(cu
    rrent)?????(prev),??prev????current?

32
??????(?????????)
  • ????????????
  • ????Mary???del_data?????Mary,??????????????
    current????Mary???,?prev??John??,??current????
    ????

33
??????(?????????)
?
34
??????(????????????)
  • ?????????
  • ?x?y?????z??,?????

35
??????(????????????)
36
??????(????????????)
37
??????(????????????)
38
??????(??????)
  • ????,?????(invert)?????????????,??,???????????
    ???????????,??????????,??????????

39
??????(??????)
  • ????????
  • ?????????????????

40
??????(??????)
41
??????(??????)
42
??????(??????)
  • ??????????p??,current???prev????????????????,??
    ??

43
??????(??????)
  • ?????p NULL?,????

44
??????(??????)
  • ??,??
  • head-gtnextcurrent
  • ??????????????????????????????

45
??????(???????)
  • ???????????????,???????????????

46
??????(???????)
  • ???????????????? (p ! NULL) ????count???????
  • ??head?????????,????????

47
????
  • ??????????????????head???,?????????(circular
    list),?????
  • ?????????????????????????????x1?

48
????(????????)
  • ????????

49
????(????????)
  • ??malloc?????????
  • ?????????x????????????????

50
????(????????)
51
????(????????)
52
????(????????)
53
????(????????)
3. ??????????????????,???????????
54
????(???????)
  • ?????????
  • ????????????????

55
????(???????)
?
?
56
????(???????)
  • ??p??????,?????????????

57
????(???????)
  • ????????
  • ?????????????????

58
????(???????)
59
????(???????)
?
60
????(??????)
  • ????????????????????,???
  • ????

61
????(?????????)
  • ?????????,????????????????????

62
??????
  • ??????(doubly linked list)?????????????,?????(L
    LINK),????(DATA),?????(RLINK),???????

63
??????
  • ??LLINK??????,?RLINK????????????????????????,??
    ?????????????????

64
??????
  • ??????????????
  • 1.??ptr??????????,?
  • ptr ptr-gtllink-gtrlink
    ptr-gtrlink-gtllink
  • 2.?????????????,??
  • ???????

65
??????(???????)
  • ?????????????
  • ???????????????x ??????

66
??????(???????)
?
?
?
67
??????(???????)
?
?
68
??????(???????)
  • ????????????
  • ???????????????x ???????

69
??????(???????)
?
70
??????(???????)
?
?
71
??????(???????)
  • ??(2), (3)????????

?
?
72
??????(?????????)
  • ????????????,???
  • ?????????,???????
  • ??????????(?????
  • ?)

73
??????(?????????)
74
??????(?????????)
75
??????(?????????)
76
??????(???????)
  • ???????????,????

?
?
?

?
77
??????(???????)
?
?
78
??????(???????)
79
??????(???????)
  • ?????????

?
?
80
??????(???????)
?
81
??????(???????)
82
??????(?????????)
  • ????del_dat?cd,???????

83
??????(?????????)
?
?
84
??????(?????????)
85
???????
  • ?????????
  • ?????????????????,??,?????????????????????,??????
    ?????????????????????
  • ?????????
  • ???????????????,????????????????????,??????????
    ???

86
???????(?????)
  • ??????????????????????????????,???????
  • COEF???????,EXP???????,?LINK???????????

87
???????(?????)
  1. ??????? A3x142x81,???????
  2. ???????????????

88
???????(?????)
89
???????(?????)
  • 1. ??A?B??????????EXP
  • ???(EXP(p) EXP(q)),???
  • ????C??,??p?q????
  • ???????

90
???????(?????)
91
???????(?????)
  • 2. EXP(p)8ltEXP(q)10????B?
  • ??????????C???,?
  • ?q??????????

92
???????(?????)
93
???????(?????)
  • 3. ??EXP(p)8gtEXP(q)6,???A
  • ???????????C???,p
  • ??????????

94
???????(?????)
95
???????(?????)
  • 4. ??????C????
  • C11x14-3x102x810x61
Write a Comment
User Comments (0)
About PowerShow.com