Title: Application of Linked Lists
1Application of Linked Lists
- ?????????????????????? (Single Variable
Polynomial) - ?????????????????????? (Sorting)
?????????????????????? (Linear time) - ??????????????????????????????????????????????????
????????????????????
2????????????????????????? (Polynomial ADT)
- ????????????????? (Single Variable Polynomial)
- Ai ??????????????????? (Co-efficient) ???????
- i ?????????????????? (Degree) ???????
- ??????????????????????????????????????????????????
????? - ???? 8X3 35X2 X 24
3Polynomial ADT
- ????? Abstract Data Type ????????????
(Polynomial) ?????????????????????????
??????????????????????????? (Array)
???????????????? (Linked List) - ?????????????????? (Coefficient) ???????????????
0 (???????????????????) ??????????????????????????
??????????????????????????? - ?????????????????????????????????????
(Operations) ???????????????????????? ???? ??????
(addition), ?????? (multiplication)
4????????? Polynomial ADT ???????????????????????
- ?????????????????????? Structure
- ?????????????????????????????????????????????
- ????? (Index) ????????????????????????????????????
???????
5????????? Polynomial ADT ???????????????????????
- ???????????????????????
- ???????????????????????????????????
- ????? (Index) ????????????????????????????????????
??????? - ???????? 8X3 35X2 X 24
X 8 35 1 24
x3 x2 x1 x0
6????????? Polynomial ADT ???????????????????????
X5 X4 X3 X2 X1 X0
X
0
14
23
1
6
0
X5 2X4 34X3 17X
X5 X4 X3 X2 X1 X0
X
34
2
0
1
0
17
7????????? Polynomial ADT ???????????????????????
- ?????????????????????????????????????????????????
0 ??? ????????????????????????????????????????????
?? - ??????????????????????????????????????????
????????????????????????????????
????????????????????????????????? - ??????????????????????????????????????????????????
????????????????????????????????????????????
8Structure ??????????????????????????????
- maxDegree
- ?????????????????????????????????????????????????
??????? ????????????????????????????????????????? - coefficientArray
- ??????????????????????????????????
???????????????????????? maxDegree1 - highestPower
- ???????????????????????????????????????????????
????????????????????????????????????
9Structure ??????????????????????????????
Struct Polynomial int CoefficientArray
MaxDegree1 int HighestPower
Polynomial
int CoefficientArrayMaxDegree1
int HighestPower
10?????????????????????? Polynomial ????????????
- ???????????????? CoefficientArray ??????????? 0
- ?????????????????????????? HighestPower ???? 0
Algorithm makeZeroPolynomial(polyterm) maxDegree
the highest possible degree of
polynomial polyterm pointer to the polynomial
structure i index to current member of
array Begin for(int i 0 i lt maxDegree
i) (Set CoefficientArrayi of polyTerm to
0) (Set HighestPower to 0) End
11???????????????????
- ????????????? Polynomial ?????? 3 ???
- poly1, poly2 ????????????????????
- polySum ??????????????????????????
- ??????????????????????????????????????????????????
??????? (Highest Power) ???????????????? - ???????????? ?????????????????????????????????????
???????????????????????????
12???????????????????
- Algorithm addPolynomial(poly1, poly2, polySum)
- maxDegree the highest possible degree of
polynomial - poly1,poly2 polynomial terms to be added
together - polySum resulted polynomial
- i index to current member of array
- Begin
- (Call Procedure MakeZeroPolynomial(polySum))
- (HighestPower of polySum maximum between
HighestPower of poly1 and HighestPower of poly2) - for(i(HighestPower of polySum) igt0 i--)
-
- (CoefficientArrayi of polySum)
(CoefficientArrayi of poly1)
(CoefficientArrayi of poly2) -
- End
13???????? Polynomial ??? Linked List
- ??????? Running Time ?????????????????????????????
??????????????????????????????????????????
(Coefficient) ???? 0 - ???????????? Linked List ????????????????????????
? ???????????????????????? 2 ??? - ???????????????????????????????? (Coefficient)
??????? - ????????????????????????????????????? (Degree)
???????
575X620 10X114 3X17 45
NULL
14????????? Polynomial ADT ??????????????? Linked
List
Structure PolyNode int coeff int
exponent PolyNode next
next
15???????? Polynomial ??? Linked List
68X34 26X12 7X 33
NULL
X10 X
NULL
16Radix Sort
- ????????????? (Sorting) ?????? 10
- ????? Bucket ????????????? ???????????????????????
?????????????? ???????????????????????????????????
????????????? Sort - ???????????????????????? Bucket
?????????????????? List - ??????????? (Sorting) ????????????????????????????
????????? - ?????????????????????????????????????????????????
(Less significant digit) ?????????????????????????
?????? (Most significant digit) - ?????????????????????? ???????????????????????????
??????????? ???????????? list ???????? - ??????????????????????????????????????????????
17?????? Input ???? 64, 8, 216, 512, 27, 729, 0, 1,
343, 125 ????????????????
0 1 2 3 4 5 6 7 8 9
64
8
216
512
27
729
0
1
343
125
?????????????????????? Bucket ???????? ?????????
0, 1, 512, 343, 64, 125, 216, 27, 8, 729
18????????????????????? 0, 1, 512, 343, 64, 125,
216, 27, 8, 729 ??????????????
0 1 2 3 4 5 6 7 8 9
8
729
1
216
27
0
512
343
64
125
?????????????????????? Bucket ???????? ?????????
0, 1, 8, 512, 216, 125, 27, 729, 343, 64
19????????????????????? 0, 1, 8, 512, 216, 125,
27, 729, 343, 64 ???????????????
0 1 2 3 4 5 6 7 8 9
64
27
8
1
512
216
125
729
343
0
?????????????????????? Bucket ???????? ?????????
0, 1, 8, 27, 64, 125, 216, 343, 512, 729