0% found this document useful (1 vote)
124 views

Data Structure

Its a good book in data structure
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
124 views

Data Structure

Its a good book in data structure
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1019

:

C++

C++



C++

:

:

2003 .
.
C++ builder .
codeWarrior .Metrowerks visual C++ 6.0
visual Studio NET PowerPoint .
pentium IBM .

.

3 4 5 6 7 8 9 WC 07 06
25 .02210
www.course.com :
.

.
:
(800) 730-2214 :
(800) 730-2215 :
www.thomsonrights.com

:
.
.
. .
ISBN 0-619-15907-3


:
.1 C++
.2 C++
.3
.4
.5
.6
.7
.8
.9
.10
.11
.12
.13 2




-
C++
C++

25
27
161
234
303
394
433
490
548
584
644
727
777
859
860
861
863
864
870
880
903
905
919

.1 C++

25

26

27

27

28

29

30

: O

32

37

39

)(

40

41

45

45

47

48

)(

49

50

52

57

57
59

62

68

69

72

75
83

C++

92

92

95

98

104

103

106

109

119

110

111

112

113

114

115

this

116

120

122
123


) (

125

) (

126

)<<( )>>(

127

)<<(

127

)>>(

128

130

132

135

136

136

142

146

148

148

152

158

161

.3

162

165

)&(

166

)*(

168

170

173
175

176

179

180

181

183

185

187

190

193

)] [(

195

newString :

196

180

195
198

201

228

230

243

.4

243

243

244

vector :

245

vector

246

vector

247

255

228

229

ostream copy

231

deque :

233

260

274

281

286

290

297

.5

303

304

305

307

311

313

315

317

319

320

320

322

322

323
324

325

326

328

330

331

331

331

332

333

333

334

337

337

341

342

343

346

247

isEmptyList

348

348

348

348

349

350

353

354

354

367

list :

350

header

355

356

10

367

367

378

383

.6

394

368

371

371

372

390

391

391

394

395

398

399

402

.7

433

433

434

436

339

340

341

441

441

442

442

443

445

446

11

)=(

446

447

447

448

452

452

457

457

457

458

linkedListType

459

: postfix

461

467

469

472

) stack (

480

482

482

485

.8

490

470

470

471

484

addQueue front backdeleteQueue

487

linkedListType

488

) queue (

492

493

priority_queue

494

494

495

12

496

499

502

507

517

517

521

.9

523

524

526

529

529

533

535

537

538

539

540

540

545

547

: ) (

549

551

552

555

557

.10

559

560

560

566

566

13

573

578

578

579

586

587

589

591

595

595

596

604

) (

605

606

626

627

628

631

.11

632

638

639

639

640

640

643

651

655

656

658

666

668

14

668

670

671

672

) AVL (

675

AVL

679

AVL

685

AVL

699

: AVL

700

: ) (

701

710

712

716

.12

719

720

721

723

723

724

726

) (

727

728

731

732

734

737

738

744

754

755

762

15

763

766

.13 2

769

pair

770

pair

771

pair make_pair

772

774

set :multiset

775

map :multimap

780

785

786

786

786

787

788

788

789

794

794

796

fillfill_n

796

generategenerate_n

798

find find_if find_endfind_first_of

800

remove remove_if remove_copyremove_copy_if

802

replace replace_if replace_copyreplace_copy_if

806

swap iter_swapswap_ranges

808

search search_n sortbinary_search

811

adjacent_find mergeinplace_merge

815

reverse reverse_copy rotaterotate_copy

818

count count_if max max_elementmin


821

min_elementrandom_shuffle

16

825

for_eachtransform
includes set_intersectionset_union
set_differenceset_symmetric_difference

827

accumulateadjacent_difference
835

inner_productpartial_sum

840

844

846

847

849

851

855

857

cassert

857

cctype

857

cmatch

859

cstddef

860

cstring

860

string

861

865

)( C++

865

871

872

C++

875

875

876

876

:C++

877

C++

878

879

879

17

882

887

889

890

895

895

void

896

898

898

900

900

901

901

903
905

905

906

907

908

909

909

910

911

912

10

913

11

914

12

916

13

918

919

18


.C++
C++ .


.
:C++
.

.
.
.
C++

)( .

)( C++
)( .

:

.
.

O .
. C++ .
.
.
.

19

2
) . ( .
C++ .
C++ : .
) ( .
1 3 .C++
3 .
.
C++ .
) ( . 4

. vector.deque

.
5

. 5 header
trailer . .list
6
.
7 8

stack) queue ( .
.
9
.
.

.10 11
12
.

20

13 4
.
) ( C++ )(
.C++ )(
. )( C++ .
)( . )(
C++ . )(
C++ C++
.
)( .C++ )(
C++ )(.
)( .
:
C++
.
. C++
.
.
4
.
.
4 .
6 6 7 .8
6 " " 7
.6 6 9
9 10 . 6 .9
.

21

:1
:

.
C++ .
.
350
.

.

.


22

.
.
. .
.
.C++
C++ .
C++ .

.
.
.
.
C++ .
.
.
.
.
C++ .
:
.
.
: :

.
.
:
) (LAN .

.

.

23

:

.
.
: WebCT
Blackboard MyCourse.com
.

.21
.
.
: www.course.com
. .
:A
: www.course.com
.
. :A
:

:

.
.

.
.

.

.
.

24

:
[email protected]

25


1

C++
:
.
.
.
.
.
.
.
constructors & destructors
.
.
.
.C++
" " .
.

. .

.
.

26

.
""
.
.

.
""
.

.
.

.

.
:

. :
.
.
.

.
/ .
) ( .
.

.

27



. .
:
:
.
.
.
.
.
:
:
.
:

.

.

.
.
.

.
.

.

28

:

.
:
.
:

.

. .
.
:

""
.
. .

.
.

.
.
.
.
.
.
:
.
.
.

29

C++ " " .


.C++ 2
.

.
:

.
) (

.
.

.
.
. . .
.
1 = 2.54 . .

cerr cout
) ( cerr
.

1.0- .
.

30


. .1.0-
.
: .
: .
:
: .
: > 0 1.0-
.

C++ .
:
: .
: > 0
.


.
.
cassert .
assert
. define NDEBUG >.# include <cassert

31

.
.
:
;)Double inchesToCentimeters (double inches
: .
: > 0 1.0-
.

.
.
;)Bool search (int list [ ], int listLength, int searchItem
: .
:
.
:
""
"" .
.
.
.
) ( .

.
.

. .

) ( .
.
. .
.

32


.
.
.
.
.
.
.
isWithinRange )(
.100
.
isWithinRange 1.0- : 1 99 100
500- 1.0- 1 50 99 100 101.500
.
.
.
.
.
: O:

.

.
.
.
.
. 50 50

) .(1-1

33

...

49

50

:1-1 .
.2-1
.2-1

:2-1 .
50

. 3-1 .

:3-1 .
:
50 = 1 + ... + 1 + 1 + 1.
:
100 = 50 + 50.
50 .
:
. 2
. 3
. 4-1 .

34

:4-1 .

.
:
2550 = (50 + ... + 3 + 2 + 1) *2.
n n
.4-1
:

) (1-1 .n ) (2-1
n

n .
1-1 ) (1-1) (2-1 ) .n
:1-1 n n2

+n

:
+n

2n

10

10

20

100

100

200

10000

1000

2000

1000000

10.000

20.000

100.000.000

35

.
(.

.


.
. :
:1-1
) (.

1 >> 2 >> 3 <<


4 =< 5 = 7 =
8 >> . 5 7 .
.9 = 3 + 1 + 1 + 2 + 1 + 1
.

:2-1
:

36

5 ) 1 (4 9 8
11 13.
5 4 ) 6 .(8 5
8 5 . 10 10 .
5 . 51
5 .8
10 :
9 + 5 + 1 + 5 *10 8 + 5 + 1 + 5 *10
:
15 + 5 *10 14 + 5 *10
n n
:
5n + 15 5n + 14
n 5n 15
14.
.
.6

. .
.

.

37

.

.
) f(n n .
.
.n
.9 .
.
n ) f(n ) f(n
.
c .
) f(n ) .cf(n c
. ) f(n .
) f(n . .2-1
2-1 :
n

log2n

Nlog2n

2n

16

15

24

64

256

16

64

256

65.536

32

160

1.024

4.298.967.296

2-1 n .
. 2-1

= ) f(n

.
.
1 3-1
) f(n.

38

n
10

s 0.01

s 0.003

s 0.033

s 0.1

20

s0.02

s 0.004

s 0.086

s 0.4

ms1

30

s 0.03

s 0.005

s 0.147

s 0.9

s1

= s 1

= ms 1

3-1 ) f(n 1 )(
n
4

0.04

0.005

0.218

50

0.05

0.006

0.282

100

0.10

0.007

0.664

1000

1.00

0.010

9.966

10.000

10

0.013

130

100.000

0.10

0.017

1.67

1.000.000

0.01

10.000.000

0.10

100.000.000

1.00

= s 1

= ms 1

) f(n n .
.
"".
: f .n "" f n .

. g

n g . .4-1
:4-1

n
360

100

10

2720

2500

50

10.420

10.000

100

1.004.020

1.000.000

1.000

100.040.020

100.000.000

10.000

39

4-1 n 4n+20 ) f(n

. n ) f(n ) .g(n

f g f g .
: ) f(n
c

5-1 Big-O .
n .
:5-1 Big-O :
)f(n

)g(n

) (1-1 ) O(n ) (2-1


1-1 ) O(1 2
).O(n
.C++


. C++
"" .C++
.
:

40

classMemberList / .
) ( .
.
.
.
) (
.
.
.
C++ .
);( .
.
:
. .
:
.
.
.
.
C++ .
:3-1
clockType .
:
. :
-1 .
-2 .
-3 .
-4 .
-5 .
-6 .

41

-7 .
clockType 10 :
.
clockType .
.

. .
.
.
:
.
).(setTime
) clockType (:
:
:
) (
// .
// .
// : = = = .
//
.
) (
// .
// : = = = .
)(
// .
// : ::.
) (
// .
// : .
// 23:59:59 00:00:53

42

) (
// .
// : .
// 23:45:53 00:45:53
Bool )(const clockType& otherClock
// .
// : .
:
// Int hr .
// Int min .
// Int sec .
:clockType
:
.
.
.


. .
equalTime otherClock
equalTime otherClock
otherTime .
OtherClock OtherClock
) . "
)(" (.
const printTime equalTime
.clockType
) ( C++
.
. ) ( public
. private

43

) public (clockType
)( .
clockType private
.public private .

.private
.public
clockType
.
setTime hr, min, & sec .
.setTime printTime

& hr, min,

.sec ) (incrementSeconds
) (incrementMinutes
) (incrementHours )(equalTime
.
:
.
5-1 .clockType

:5-1 .clockType

44


.
) (+ ) (-
) (# .
)(:
. C++
.
.
.
:clockType
;myClock

clockType

;yourClock

clockType

10 :
.hr, min, & sec
myClock 5 12 30
yourClock 12 35 45 .
. C++

.
:

:
classVariableName.memberName
C++ ) (. . 4-1
.
:4-1
:
;)myClock.setTime (5, 2, 30
;) ( myClock.printTime
;)yourClock.setTime (x, y, z

45

x, y, z int
))(myClock.equalTime (yourClock
.
.
.
.
) myClock.setTime (5, 2, 30 .setTime
5 2 30 setTime
hr, min, & sec myClock 5 2 30 .
printTime
.myClock x, y, z
.yourClock
equalTime
myClock .yourClock
equalTime myClock
.myClock
yourClock . equalTime .

) (hr, min, & sec clockType
:myClock

:
C++
) .(2
) (+ clockType
)
.(2

46

) ( . )=( .
.
.
:
myClock yourClock clockType .
myClock yourClock

.6-1

:6-1 myClock yourClock


:
// Line 1

;myClock = yourClock

yourClock myClock :
.1 yourClock.hr .myClock.hr
.2 yourClock.min .myClock.min
.3 yourClock.sec .myClock.sec
yourClock
.myClock .
myClock yourClock .7-1

47

:7-1 myClock yourClock

= myClock

yourClock
:
)
( )
( .
. .
.
) .( .
:
:
.
.

.
)(:

.
.

. .

.
.

.
.
. C++
const .
:

48

testTime .otherTime otherTime


.const testTime
otherTime otherTime
. :myClock
;)testTime (myClock

const .

)
( .
.
testTime .otherTime
:testTime
:
clockType .
.
.
.
.
clockType
setTime getTime printTime incrementTime equlaTime .
setTime printTime ) (
.
.
. setTime :

49

setTime .
.
) hr( .
myClock ) clockType ( :
;)myClock.setTime (3, 48, 52
myClock .8-1

:8-1 myClock .myClock.setTime


clockType
:

50

51

incrementMinutes incrementSeconds
.
equalTime :

.equalTime
myClock yourClock clockType
. myClock yourClock .9-1

:9-1 myClock.yourClock
:
))If (myClock.equalTime (yourClock
:
)myClock.equalTime (yourClock
myClock .equalTime yourClock
otherClock .10-1

52

:10-1 myClock .otherClock


) hr, min, & sec ( 14 2554
. equalTime 14 otherClock.hr
otherClock.min 25 otherClock.sec .54 equlaTime
.myClock equalTime hr, min, & sec
) ( equalTime .myClock
hr myClock otherClock.hr min
myClock otherClock.min sec myClock
.otherClock.sec
equalTime .
:
:

2 ) hr, min, & sec (


myClock 6 27 46 3
:
06:27:46
3
C++
. ) (
setTime
.
:
. : .
:
.

.

53


.


.



.
clockType .
clockType
}
:
;)Void setTime (int hours, int minutes, int seconds
// .
// .
// = hr : = min = sec.
//
// .
// .
;)Void getTime (int hours, int minutes, int seconds
// .
// = hr : = min = sec.
;Void printTime ( ) const
// .
// :
//

.hh:mm:ss

;) ( Void incrementSeconds
// .
// : .
// 23:59:59

54

// 00:00:00
;) ( Void incrementMinutes
// .
// : .
// 23:59:53
// 00:00:53
;) ( Void incrementHours
// .
// : .
// 23:45:53
// 00:45:53
;bool equalTime (const clockType& otherClock) const
// .
// :
//

otherClock

//

;)clockType (int hours, int minutes, int seconds


// .
// .
// = hr : = min = sec
///
// .
// .
;) ( clockType
// .
// .
// 0 = hr : 0 = min0 = sec

55

:
Int hr

// .

// Int min .
Int sec

// .

;}
clockType :
. .

hr,

) min, & sec ( .


.
setTime :


.setTime

56

:
.
.
: .
:
ClassName

classVariableName
:
;clockType yourClock

yourClock clockType
yourClock .

.
. :
// illegal

;) ( clockType yourClock

: .
:

;) classVariableName (argument1, argument2,

ClassName

argument 1 argument2 .
:
) (
.
) ( C++
.

.
:
;)clockType myClock (5, 12, 40

57

myClock .clockType int


.
clockType
myClock 5 12 40 .
:

.
.
clockType
) . (.

.
clockType ) 1 (
clockType 0 1 2 3 :

clock1 hr clock2 5
min sec clock2 . hr clock3
12 min clock3 30 sec clock3
. hr clock4 7 min clock4
34 sec clock4 .18

.
:
.
.

58

. )~( )
)~( ( . clockType:
;) ( ~ clockType
.
.
:
.
. C++ .

. .
:
.

.
.
. .
) ( .
.
.
.
.
.
clockType :
.1 .
.2 .
.3 .
.4 .
.5 .

59

.6 .
.7 .
.clockType
. clockType
clockType
.clockType
: .
)( )(.
:

.
clockType :

clockType

clockType
.
:
.
.
.
.
.
.
.
:5-1
.
.
:

listType

60


listType 1000 .

.
.
.
.
.
.
.
.
.
.
.
.
. C++
.
) .(11-1
.int
Class intListType
}
:
;) ( Bool isEmpty
// .
// : .
:
.
;) ( Bool isFull
// .
// : .
:

61

.
;)Int search (int searchItem
//
// .
// :
//

//

//

.1-

;)Void insert (int newItem


// .
// : .
// :
.
;)Void remove (int removeItem
// .
// : .
// :
//

//

;) ( Void destroy
// .
// : .
// : .
;) ( Void printLisy
// .
// : .
// :
//

;) ( inListType
//
// : = .

62

:
;]Int list [1000
;Int length
;}
inListType
] [ -list: int
-length: int
+ isEmpty ( ) : bool
+isFull ( ): bool
+search (int) : int
+insert (int) : void
+remove (int) : void
+destroy ( ) : void
+printList ( ) : void
) ( +intListType
:11-1 .intListType
:
clockType .
. clockType
.
. C++
.
clockType
.
.
.
clockType .
clockType
clockType .
.
.

63

.

. .
) (.
.
) ( .C++ C++
.main
.main Main
. .

.
h .cpp
clockType clockType
.clockType.h clockType
clockTypeImp .clockTypeImp.cpp
clockTypeImp.cpp .
) (
clockType.h clockTypeImp.cpp .
clockType
:clockType
"# include "clockType.h
clockType.h .
clockType.h .

) (iostream .
:clockType
clockType.h // clockType
clockType
}
:

64

;)Void setTime (int hours, int minutes, int seconds


// .
// .
// = hr : = min = sec.
//
// .
// .
;)Void getTime (int& hours, int& minutes, int& seconds
// .
// = hr : = min = sec.
;Void printTime ( ) const
// .
// :
//

.hh:mm:ss

;) ( Void incrementSeconds
// .
// : .
// 23:59:59
// 00:00:00
;) ( Void incrementMinutes
// .
// : .
// 23:59:53
// 00:00:53
;) ( Void incrementHours
// .
// : .

65

// 23:45:53
// 00:45:53
;bool equalTime (const clockType& otherClock) const
// .
// :
//

otherClock

//

;)clockType (int hours, int minutes, int seconds


// .
// .
// = hr : = min = sec
///
// .
// .
;) ( clockType
// .
// .
// 0 = hr : 0 = min0 = sec
:
Int hr

// .

// Int min .
Int sec

// .

;}
// clockTypeImp.cpp, the implementation file
># include <iostream
"# include "clockType.h
;Using namespace std

66

.
.
.
// clockType .
.
.
.
.clockType
// testClock.cpp
// .clockType
># include <iostream
"# include "clockType.h
;Using namespace std
.
.
.
// main .
.
.
.
6-1 . personType 6-1
.
:6-1
.
. personType
) 12-1 (.
personType
}
;Void print ( ) const
// .

67

// .
;)Void setName (string first, string last
//
// .
// : = first = .last
;)Void getName (string first, string& last
//
//.
// = first : = last .
;)" " = personType (string first = " ", string last
//
//
//.
// .
// : = first = .last
:
; // String firstName .
;String lastName

// .

{
personType
-firstName: string
-lastName: string
+print ( ): void
+setName (string, string): void
+getName (string, string): void
)" " = +personType (string = " ". string

68

12-1 personType
.personType

: :

.
. .
:
.1 .
.2 .
.3 .
.4 .
.5 .
: .
: .
:
.

69

:
. .
.
.
.
) .(13-1
cashRegister
}
:
;) ( Int currentBalance
// .
// : .
;)Void acceptAmount (int amountIn
//
// .
// : = + .
;)cashRegister (int cashIn = 500
//
// .
// : = .
//
//
// .500
:
;Int cashOnHand

//
// .

{
cashRegister
-cashOnHand: int
+currentBalance ( ) : int

70

+ acceptAmount (int) : void


)+cashRegister (int = 500
:13-1 cashRegister
.cashRegister
.
currentBalance
.cashOnHand :
) ( Int cashRegister : : currectBalance
}
;Return cashOnHand
{
acceptAmount
.
:
)Void cashRegister : : acceptAmount (int amountIn
}
;casgOnHand += amountIn
{
cashRegister

.cashOnHand

. :
)cashRegister : : cashRegister (int cashIn
}
)If (cashIn >= 0
;cashOnHand = cashIn
else
;cashOnHand = 500
{

71

.cashIn cashIn
cashOnHand .500
:
.
. .
) .dispenserType .(14-1
dispenserType
}
:
;) ( Int count
// .
// : ) numberOfItems (.
;) ( Int productCost
// .
// ) cost(.
// : .
;) ( Void makeSale
// .1
// ) numberOfItems : .(--
;)dispenserType (int setNoOfItems = 50, int setCost = 50
// .
// NumberOfItems = setNoOfItems; :
//

cost = setCost

//
// .

72

:
;Int numberOfItems

// .

;Int cost
;{

// .

dispenserType
-numberOfItems : int
-cost : int
+count ( ) : int
+productCost ( ) : int
+makeSale ( ) : void
)+dispenserType (int = 50, int = 50
:14-1 .dispenserType

dispenserTyppe :
;)dispenserType chips (100, 65
dispenserType
100 65 ) .

-1

.(15

:15-1 .
.dispenserType
count .
numberOfItems
.numberOfItems
:
) ( Int dispenserType : : count
73

}
;Return numberOfItems
{
productCost cost
)( .cost :
) ( Int dispenserType : : productCost
}
;Return cost
{
1
makeSale .1
numberOfItems 1 :
) ( Void dispenserType : : makeSale
}
;numberOfItems--
{

:
// constructor
)dispenserTyoe : : dispenserType (int setNoOfItems, int setCost
{
)If (setNoOfItems >= 0
;numberOfItems = setNoOfItems
else
;numberOfItems = 50
)If (setCost >= 0
;Cost = setCost
else
;cost = 50
}
:
:
.1 .
.2 .
.3 .
74

) (
.
.

.
.
:
.1 .
.2 .
.3 .
:
).(showSelection, sellProduct, & main
:showSelection
.
) .
(.
*** ***"

1
2
3
4
9
showSelection:
) ( Void showSelection
{
;Cout <<"*** Welcome to Shelly's Candy Shop *** <<end1
;cout <<"To select an item, enter"<<end1
;cout <<"1 for Candy"<<end1
;cout <<"2 for Chips"<<end1
;cout <<"3 for Gum"<<end1

75

;cout <<"4 for Cookies"<<end1


;cout <<"9 for exit"<<end1
}// end showSelection
sellProduct
.
.
.
.
sellProduct
)
(9 .
. 1
) .
(.
sellProduct
) 1 ( )
( . : .
.
:
. :
.1 .
.2 .
.3 :
. .
. .
.4 :
. .
. .1
. .
.5 .
. .

76

sellProduct:

showSelection ) sellProduct (
.main
:main main :
.1 .cashRegister
.2 dispenserType
. :
;)dispenserType candy (100, 50
. 100
50.
.3 .
77

.4 .shoeSelection
.5 .
.6 ) 9 (:
. .sellProduct
. .showSelection
. .
main :

78

// main.
// showSelection.
// sellProduct.
: .
*** ***"

1
2
3
4
9
1
50
50

**-*-*-*-*-*-*-*-*-*-*-
*** ***"

1
2
3

79

4
9
3
45
45

**-*-*-*-*-*-*-*-*-*-*-
*** ***"

1
2
3
4
9
9


.

.
.
:
.
.

cylinderType .
.
:
.
.
.

80

.
cylinderType
.
.
. :
cylinderVolume ) cylinderSurfacaArea (.
.


.
:
.1 .
.2
.
.3 .
.4 .
.5 ) ( /
.
.6 .
.7 : .
.8 .
.9
.
.10
.
.11 .
.

81

.12
.
.13 .
.14 :
.
.15
.
.16 .
.17 .
.18
.
.19 .
.20 .
.21
.
.22 .
.23 .
.24 .n "" n
.
.25 .
.26 .
.27 .
.28 C++ .
.29 : .
.30 .
.31 .
.32 .
.33 ) private(.
.34 ) Public(.
.35 ) (.

82

.36 .
.37 .
.38 .
.39

. ) (+
) (- .
) (# .
.40 C++ .
.
.41 C++ .
.42 ) (0 .
.43 .
.44 .
.45 .
.46 .
.47 .
.48 .
.49 .
.50 .
.51 .
.52 .
.53 )~( ) (.
.54
. .
.55
.
.56
.

83

.57
. ) (
.
:
.1 :
.
.
. .
).o(n

. .
. .
. .
. .
. .
.2 :
;)Double sqrt (double x

.3 .

.
.
.
.
.4 :
)Void funcExercise4 (int x, int y
{
;Int z
;z = x + y
;x = y
;y = z
;z = x
;cout<<"x = "<<x<<", y = "<<y<<", z = "<<z<<end1
}
84

.funcExercize4
.5 :
)Int funcExercise5 (int list [ ], int size
{
;int sum = 0
)for (int index = 0; index < size; index++
;]Sum = sum + list [index
;return sum
}
. funcExcercise5
.10
. funcExcercise5
.n
. funcExercise5
.6 :
;)Int funcExercise6 (int x
funcExercise6 : 50= > x =>0 2x
0= > x =>50- .999- funcExecise6
.7 assert .
.8 1.n

.9
.10
.11 :

85

.12 :

. xClass
. xClass
. xClass
. func u 10 w .15.3
86

. print u.w
. xClass
.
. C++ .x
. C++ xClass t
20 35.0 .
.13 :

.
:
.1

CC one

.2

)CC two (5, 6

.3

)CC three (3, 5, 8

. 1 .
. 2 u
v .
. 3 4
.

87

.14 :

. .testClass
. .testClass
:
.1 .clockType
.2 .
romanType romanType
:
. .
. .
. .
:
1000 M
500
D
100
C
50
L
10
X
5
V
1
I

88

. MCXIV :CCCLIX
.MDCLXVI
.3 dayType .
dayType .
:dayType
. .
. .
. .
. .
. .
. DayType .
4 .
13 .
. .
.4 dayType
3 .dayType
.5 6-1 personType
. personType
:
-

- .
- .
- .
- .
- .
.6
. : ISBN
. bookType .

89

bookType :
ISBN .
.
.bookType

.

. ISBN
. ) (.
. .bookType
. bookType
.bookType 100 .bookType
ISBN
.
.7 .memberType
-

memberType
.

- memberType

.
- ) (.
- .memberType
.8 6 7 .
:
. 10 %5
.
.

.

90

1000 500 .

.
.9 sellProduct
. sellProduct
. .
.7
. : ISBN
. bookType .
bookType :
ISBN .
.
.bookType

.

. ISBN
. ) (.
. .bookType
. bookType
.bookType 100 .bookType
ISBN
.
.7 .memberType
- memberType
.
- memberType

.
- ) (.
- .memberType

91

.8 6 7 .
:
. 10 %5
.
.

.
1000 500 .

.
.9 sellProduct
. sellProduct
. .

92


2

C++
:
***********
************


.C++ .
.
.
.
.
:
partTimeEmployee
.
. ) 6-1 (1
. partTimeEmployee
) personType (6-1
) / (.

- personType

personType .
partTimeEmployee personType
. personType
.partTimeEmployee
) personType
.(2-2

93

clockType
. clockType .
.
clockType extClockType
. extClockType
clockType . C++
. ""is-a
" ".
.
.
.
.
.
.
.
.

. 1-2
.

1-2 .

94


. .
:
Class className : memberAccessSpecifier baseClassName
{
Member list
;}
:
}

{
.
) . (.
:

.
.

.
.
/ .


.
.
.
) ( ) .
(.

95

:1-2
.shape
)( ) Circle( ) shape( :

)(

:circle

)(

) Circle( ) shape (

. shape .circle
circle .
circle

.
.
.
.

.
:
derivedClass baseClas
derivedClass baseClass .
derivedClass .baseClass

96

baseClass print .baseClass


derivedClass
.baseClass .deruvedClass
. derivedClass
print ) .(baseClass
) ( .
.

.
.

.
:

baseClass . ) print (
baseClass:

97

derivedClass derivedClass
baseClass . baseClass
.derivedClass derivedClass .print
print .derived Class
derivedClass u v ch first .second
print derivedClass . print
derivedClass :
u v ch baseCleass
.derivedClass print derivedClass
u v ch .
u v ch baseClass derivedClass
.baseClass
) print ( derivedClass
print baseClass u v .ch u v ch
.first & second
print baseClass print derivedClass
:
;) ( baseClass : : print
print baseClass .derivedClass
print derivedClass:

98

:
.
.

. .
.
) (

.
.
.
.
.
) :(2-2

baseClass
-u : int
-v : int
-ch : char
+print ( ) : void
) ( +baseClass
)+baseClass (int, int
)+baseClass (int, int, char
:2-2 .baseClass
99

. print baseClass
: baseClass

:(3-2 )

DerivedClass
-first : int
-second : double
+print ( ) : void
+derivedClass ( )
+derivedClass (int, int, int, double)
+derivedClass (int, int, char, int, double)

100

baseClass

derivedClass

:3-2 derivedClass .
derivedClass baseClass . derivedClass
u : v ch first .second u vch
first second .baseClass
print .derivedClass

.derivedClass
.
.derivedClass
.
baseClass
derivedClass .

. ) (
.
) derivedClass 3
:(derivedClass

101

) (baseClass ) 3
.(baseClass ) (derivedClass
) int .(baseClass 3
) (derivedClass 4
):(derviedClass

) (baseClass )
.(baseClass ) (derivedClass
int int) char
.(baseClass
:2-2
.
.
. )(name
) (pay rate ) .(hours worked
. ) 6-1 (1
) (personType
)(partTimeEmployee
)) .(personType (4-2 ) (print
.

102

Class partTimeEmployee : public personType


}
:
;) ( Void print
//
//.
// ::
.
//
;) ( Double calculatePay
// .
// : .
Void setNameRateHours (string first, string last,
;)double rate, double hours
//
//
//.
// : = =
= =

103

partTimeEmployee (string first = " ", string last = " ",


double rate = 0, double hours = 0);
//
//
. //
. //
= = : //
= =

. //
. //

partTimeEmployee
-payRate : double
-hoursWorked : double
+print ( ) : void
+calculatePay ( ) : douuble
+setNameRateHours (string, string,
Double, double) : void
+partTimeEmployee (string = " ", string = " ",
Double = 0, double = 0)

:
Double payRate;
Double hoursWorked;
{

personType

partTimeEmployee

. partTimeEmployee :4-2
: partTimeEmployee

104

:
.
. .

.
personType .personType.h
partTimeEmployee

ptEmployee.h
"# include "personType.h
.partTimeEmployee ptEmployee.h :

.
iostream

.

105

:
.
. .
:

testA.h test.h ONE


.TWO testA.h :

headerTest.cpp .
test.h .testA.h
testA.h " # include "test.h
test.h . test.h
.ONE test.h
ONE .TWO
. test.h
.

106

#ifndef H-test " ."H-test


#define H-test " ."H-test
#endif " ".
: H_test H_test
#define #endif .
test.h #ifndef .#endif
.
:

.
.
.
. :
.

. .
.


.
:
B A B A
. A
.
:

107

) (memberAccessSpecifier
.
.1 .
-

A B
.B

- A B
) ( .B
- A B
) ( B .A
.2 .
-

A B
) ( .B

- A B
) ( .B
- A B
) ( B .A
.3 .
-

A B
) ( .B

- A B
) ( .B
- A B
) ( B .A
" " ) ( .
:
.
. " "has-a "
".
6-1 ) (personType
.

108

) ( .
) (personalInfo
.personType
.personalInfo
) dateType (
) personalInfo ( ) personType (
) dateType ( . .
) dateType (
. .
) dateType 5-2(:

dateType
}
:
109

;)Void setDate (int month, int day, int year


// .
// dMonth dDaydYear
// .
// = dMonth : = dDay = DYear.
;)Void getDate (int& month, int& day, int& year
// .
// : = dMonth = dDay = .dYear
;Void printDate ( ) const
//
//--.
;)dateType (int month = 1, int day = 1, int year = 1900
//
// .
// = dMonth : = dDay = DYear
//
// .
:
;Int dMonth
;Int dDay
;Int dyear
{

//
//
//

dateType
-dMonth: int
-dDay: int
-dYear: int
+setDate (int, int, int) : void
+getDate (int&, int&, int&) : void
+printDate ( ) const : void
)+dateType (int = 1, int = 1, int = 1900

:5-2 .dateType
dateType :

110

setDate
1 12
) 1 (31 2
setDate
.
:

setDate
. 2
setDate setDate
.
) personalInfoType 6-2 (:
Class personalInfoType
}
:
Void setpersonalInfo (string first, string last,
Int month, int day,
;)Int year, int ID
// .
//
111

. //
= dMonth = = : //
= personID = dYear = dDay

//

Void printpersonalInfo ( ) const;


. //
personalInfoTyoe (string first = " ", string last = " ",
int month = 1, int day = 1,
int year = 1900, int ID = 0);
//
//
. //
= dMonth = = : //
= personID = dYear = dDay

//
:

personType name;
dateType bDay;
int personID;
{
personalInfoType
-name: personType
-bDay: dateType
-personID: int
setpersonalInfo (string, string, int, int,
int, int) : void
printpersonalInfo ( ) const : void
personalInfoType (string = " ", string = " ",
int = 1, int = 1,
int = 1900, int = 0)
.personalInfoType :6-2
personalInfoType
.name bDay
.

112

:
;personalInfoType student
) student ( bDay name
. .
) bDay .(name
. )
(bDay .
:

)
( .
) name( bDay ) student(.
:personalInfo

113

.
.
: :
C++
.
. .
C++ .
.
.
.
.
.
. .
:
C++
.
:
classType
clockType . .clockType
:
;)clockType myClock (8, 23, 34
;)clockType yourClock (4, 5, 30
myClock clockType hrmin
sec myClock 8 23 34 . yourClock
clockType hr min sec myClock 4 5 30
.
:

114

myClock ) hr : min : sec : : ( .


myClock myClock
.yourClock
>>
myClock ++ myClock
C++ .
:

.
. C++


. C++ .
.
:
.
.
>> << . >>
. << .
.
+ .- + -
.
C++ .
.
.

115

) ( .
.
< = :
=>) Operator <=(
: .
:
.
:
)operatorSymbol (arguments

operator

returnType

C++ .
)=( .
.

.
:
.1 ) (
.
.2 .
.
" ".
: :
:
.
) . +
(.
.
.
.
:

116

sizeof

?:

::

*.

int .

.
:this
.

. ) (
) (
.this C++ this .
this .
test funcOne
funcOne :

x y test :
;) ( Y = x.funcOne
x y x
.y x funcOne this
funcOne x this x* this
.x
:this
:3-2
) 6-1 (
personType
. personType:

117

personType
}
:
;Void print ( ) const
// .
// :
//
;)Void setName (string first, string last
//
// .
// : = first = .last
;)personType& setFirstName (string first
// .
// : =
//
// .
;)personType& setLastName (string first
// .
// : =
//
// .
;)Void getName (string first, string& last
//
//.
// = first : = last .
;)" " = personType (string first = " ", string last

118

//
//
//.
// .
// : = first = .last
:
; // String firstName .
;String lastName

// .

{
print setTime getName ) .(6-1
setFirstName setLastName :

119

:
-- 4 :1
-- 8 :2
--12 :3
16 :3
1 2 3 1 2 3
. 2 3 .Strings 5
)1 4 4 5 .(6
7 . :
;)"Student 2.setFirstName ("Shelly"). setLastName ("Malik
:
)"Student 2.setFirstName ("Shelly
dot point

" "Shelly .2
:
)"Student2.setLastName ("Malik
."Malik" 2 9 2
11 "Chelsea" 3 13
.3 12
.3 3

120

3 .3 15
3 16 .3
:
.
.
friend ) () . friend
(.
:

classIllusFriend friendFunc
classIllusFriend .classIllusFriend
friendFunc classIllusFriend
friendFunc friendFunc
) .friendFunc 4-2 ( .

.
:

. friend
friendFunc classIllusFriend:

121

.
) ( . 4-2
.
:4-2
:

classIllusFriend friendFunc .
classIllusFriend :

:friendFunc

122

:
:aobject.x :13 32 = x :classIllusFriend
*~*~*~*~*~* *~*~*~*~*~*
45 = x :classIllusFriend
:6 45 x
88 = x :classIllusFriend
:10 friendFunc 88 x
. 17
) friendFunc (classIllusFriend aobject
. friendFunc
.
:

.
.
:
) ( ] [ <- = .
op .opOverClass
o op )
(opOverClass op opOverClass
.opOverClass
o op opOverClass
opOverClass op opOverClass
op .opOverClass

123

.
<< >>
.
.
.
:

opOverClass a .int
opOverClass .
:

x y z .opOverClass
:
C++ .

.
# ) ( .opOverClass
.
.
) ( :

124

# .opOverClass # opOverClass
:
Operator #
x y opOverClass
x#y
:
)x.operator # (y
operator# .y
operator# opOverClass x opOverClass
operator# .x
operator# operator# .
) ( :
.
) (:
;returnType operator op(const className&) const
op returnType
className .
:

:5-2
+== .opOverClass .

125

print operator+== operator :

) ( :
# ) (
.opOverClass
:
x#y
:

126

)Operator # (x, y
operator# operator#
x .y
.operator#
operator#
friend . operator# .
) ( :
.
) (:

op returnType
className .
:

)<<( )>>(:
<< >>
:
:
;Cout<<x
<< ) (cout osream
.opOverClass <<
opOverClass opOverClass
.opOverClass

127

opOverClass
.opOverClass
)<<(:
<< .
) (:
;)&Friend ostream& operator<< (ostream&, const className
:

:
.
osObject .ostream
const ) (1
.
. " "const
.
.
.ostream
<<
:
;Cout<<x<<y
.
)>>(:
>> .
) (:
;)&Friend istream& operator>> (istream&, className

128

:
.
isObject .istream

.
.istream
>>
:
;Cin>>x>>y
.
:6-2
opOverClass :

129

:main

: .
23) = u :3 (45
:4 5 :6
5) = v :7(6
28) = v + u :8(51
1 2 u v .opOverClass
3 u cout .

130

5 v cin .
7 v cout . cout 8 uv
. .
:

.
:
.
.
: :
.
) ( .

+ . +
+ .
+ .
+
. .
: :
a a + ib b . a
b .a + ib ).(a, b
:
)(a + ib) + (c + id) = (a + c) + i(b + d
)(a + ib) + (c + id) = (ac bd) + i(ad + bc
:
))(a, b) + (c, d) = ((a + c), (b + d
))(a, b) * (c, d) = ((ac bd), (ad + bc

131

complexNumber
. .
+* . x y
x + y .x * y / :
12 .
) complexType :(2-7

132

complexType
-realPart : double
-imaginaryPart : double
&+operator<<(ostream&, const complexType&) : ostream
+operator>>(istream&, complexType&) : istream7
+setComplex (const double&, const double&) : void
)+complexType (double = 0, double = 0
+operator+ (const complexType&) const : complexType
+operator* (const complexType&) const : complexType
+operator== (const complexType&) const : bool
:7-2 complexType
.complextype

<< >>.

)(a, b
a b :
. (.
. .
. .
. .
. ).
<< :

133

>>.
:
)(3, 5
3 .5
:
. .
. .
. .
. .
. .
>> :

134

135

:complexType

: .
23) = Num1 :4(34
0) = Num2 :5 (0
:6 )(3, 4) (a, b
:9 (3, 4) = num2
(26, 38) = Num3 :11
(26, 38) = (3, 4) + (23, 34) :12
(-67, 194) = (3, 4) * (23, 34) :13

136

:
.
.
.
C++ .
.
.
.
.
.
:

largerInt largerChar
. .
larger
larger :

) larger (5, 3 larger


)' ('A', '9 .

.
:

137

C++

. :
>template<class Type
;declaration

Type declaration . C++


template class
. type .
) ( .
:
" " ) (
larger
. larger :
int Char double .string
. C++ .
:
>template<class Type
;function definition
Type
.

138

larger .
x y Type
. :

.larger 5 6 ) int (
int Type .
.
.
:7-2
larger .

139

:
:1 56 = 6
:2 AB = B
:3 5.65.6 = 3.2
:6 HelloHello = Happy
:

. 1
.int int char double string
.
. listType
.
:
>template< class Type
class declaration
.
int
string .
:

140

>Template <class elemType


Class listType
}
:
;) ( bool isEmpty
// .
// : true .false
;) ( bool isFull
// .
// : true .false
;)Void search (const elemType& searchItem, bool& found
//
// : found true
.false
//

;)Void insert (const elemType& newElement

141

// .
// : .
// : .
;)Void remove (const elemType& removeElement
// .
// :
//

" ".

//

//

//

;) ( Void destroyList
// .
// : = .
;) ( Void printList
// .
;) ( listType
//
// = .
// : =
:
;] // elemType list [100 .
;int length

// .

;{
listType
.
.
. .
:
// Line 1

;ListType<int> intList

intList 100 int :


// Line 2

;ListType<string> stringList

142

stringList 100 .string


1 2 > listType<int >listType<string
> listType<elemType
elemType .
.

. insert listType:

elemType .
:
) ( )
( ) (
. .
.

.
.

. )
( ) ( .
.
.
:
.1 .

143

.2 "."is-a
.3 "."has-a
.4
.
.5 .
.6
.
.7
.
.8
.
.9 .
.10 .
.11 .
.12 .
.13
.
.14 OOD .
.15 .
.16 C++ << .
>>
.
.17 .
.18
)returnType operator operatorSymbol (parameters
.19 C++ .
.20 .
.21
. .

144

.22
.
.23

.
.24 .
.25 C++ .
.26 *. :: : .sizeof
.27 this .
.28 ) ( ] [ > -= .
.29 .
.30 .Friend
.31 C++ friend .
.32
) ( .
.33
.
.34 << >>
.
.35 C++ .
.36 .
.37 C++ template .
.38
.
.39
.
.40 :
>Template<class elemType
;Declaration

145

elemType )
( declaration . class
.
.41 .
.42 elemType
.
.43 elemType .
.44 cType func .cType
func:
>Template<class elemType
)funcType cType<elemType>: : func(formal parameters
funcType .void
.45 cType int . ; cType<int> x
x cType cType .int
:
-1 :
-

- .
- x y x y
. x y .y
- .
- C++ .
- C++ .
- .
C++ - .
- .
- .
- int.
- .
- friend .

146

- ) (++ ) (++
.
-2 .
-3 employeeType ) personType 6-1
( . .employeeType
-4 .
-5 :

147

-6 :

. yClass .xClass
.
.
)(i

)(ii

)(iii

)(iv
-7 .6
. yClass
yClass .
. xClass
xClass .
. two of yClass a
two b .two
148

-8

-9 :

. setData .two
. print .two
-10 C++

149

150

-11

151

152

-12
-13 << .mystery
<<
-14 + .strange
operator+
-15 :

. strange >>.
. strange + .
. strange == .
. strange ++ .
-16 .15
. strange + .
. strange == .
. strange ++ .
-17 :

-18 :

153

-19 :

-20
-21
-22
-23
-24 :

-25 :

sObj strange a b
.int

- strange == .
- strange .
= = strange .
-26 :

154


-
-

-27 :


.
.
-28 .


.1 clockType .
.
extClockType clockType .
.
.

155

.2 dateType
setDate .
setDate
. isLeapYear
.
.3 .
pointType .

.
.4 .
.
. circleType .

3 circleType .pointType

.
.5 .
cylinderType .
circleType .4
:
.
.6 2 dateType
. dateType
:
. .
. .
. .
. .
. .
. .
. .
156

. . 2003-12-3
31 31 .
. . 2003-18-3
77. .
. . 2003-18-3
288.
. .
2003-18-3 25 2003.-12-4
-7 dateType
6.
-8 dateType 6
24 .2003
extDateType .
extDateType .
.2003
.extDateType
-9 ) extDateType (8) dayType
(3 calendarType
.
.
dayType .
extDateType
1 . calendarType :
dayType .extDateType
calendarType 1
.1500 1500 .
.1500
calendarType :
-


.firstDayOfMonth

157

- .
- .
- .
- .
- .
- .
.10 . ) calendarType (9
.calendarType
. .
2003:

7
14
21
28

1
8
15
22
29

2
9
16
23
30

2003

4
3
11
10
18
17
25
24

5
12
19
26

6
13
20
27

.11 1 clockTime
. clockTime :
<< >>
.
.clockTime
.12 . ) complexType (
. .
) ( ) (
) ( ) - ( = ) (
) ( ) ( ) / ( = )) + ( ) / + 2(2
)- + ( ) / + 2((2
. / .
. .complexType
.
158

.13 . complexType
.
. complexType .
. complexType
.
.14 a + ib a + ib a ib a + ib
. complexType
1 1
. .
.15 14 1 .
.16 a / b a b b .
. a /b c / d .
:
a / b + c / d = (ad + bc) / bd
a / b c / d = (ad bc) / bd
a / b c / d = ac / bd
(a / b) / (c / d) = ad / bc c / d
a / b op c / d : ad op bc op
. a / b < c / d .ad < bc
. fractionType .

.
.
. C++ .fractionType
. : x y z .fraction
3/2
;Cin>>x
3/2 x
;Cout<<x+y<<end1
x+y .

159

z=x+y
x y z .
.
.17 . 2 1 romanType
. romanToDecimal
.
romanType .
String .
. .
decimalToRoman )
( . .decimalToRoman
I
v .x 4 IV 9 IX
39 XXXIX 49 .XXXXIX 40
XXXX 190 CLXXXX.
. extRomanType romanType :
extRomanType + * /
.
.extRomanType
) ( ) (
.
"
" . .
.
. .

160

. extRomanType ) . (.

161


3


************************
************************
************************

C++ : .
. : .
) (
. .
.5

162

:
.
.C++

) (
.
: ) (.
:

.
. C++
(*) astersik . :
;dataType *identifier
:
;*p

int

;*ch

char

p ch . ) p (
int ch .char p
int ch .char
.:
;*p

int


;p

*int


;* p

int

* .
:
;p, q

*int

163

p .q q .int
* . :
int

;*p, q

:
int

;*p, *q

p q .int

.

. p int p
.int C++ )&( dereferencing
)*( . .
)&(:
C++ & ampersand .
:
;x

int

;*p

int

:
;P = &x
x .p x p .
******* )*(:
(*) asterisk . C++ *
. * *****
**** . :

164

p .x :
;*p = 55
55 p .x
:
;*p

int

;num

int

p int num . int


.1-3

.
.
.
P 1200

.
.
.

num 1800
.
.
.
:1-3 p.num
1200 p 1800
.num :
;Num = 78
78 num .1800 .2-3

165

.
.
.

P 1200

.
.
.
78
.
.
.

num 1800

num :2-3 num = 78

;P = &num
num 1800 .p *p num
1800 .num .3-3

P 1200

num 1800

.
.
.
1800
.
.
.
78
.
.
.

p :3-3 .p = &num

166


;*p = 24
1800 .num .4-3

P 1200

num 1800

.
.
.
1800
.
.
.
24
.
.
.

p :4-3 num .p = 24
:
&p p *p .
&p p ) 1200 .(4-3
P 1800) p .(4-3
*p ) 24 (4-3 ) 1800 (4-3
) p .(1200
:1-3
:
;*p

int

;*x

int

p x .5-3

167

.
.
.
P 1400

.
.
.

X 1750
.
.
.
:5-3 p.x
&p p *p &x x :

&p

*****

*****

*p

****

&x

****

*******

:
;x = 50
;p = &x
;*p = 38

&p p *p &x x . :
;X = 50

168

&p p *p &x x :

&p

1400

)(

*p

) (

&x

1750

50

:
;P = &x
&p p *p &x x :

&p

1400

1750

*p

50

&x

1750

50

p = &x p x *p x
.x *p .50
:
;*p = 38
&p p *p &x x ) . *p x x
.(38

&p

1400

1750

*p

38

&x

1750

38

169

:1-3
.1 :
;int *p
p .*p
*p .*p
.2 :
;*p

int

;x

int

:
p . .
. p .int
. x .int :
p= &x
. *p .
:2-3
.

170

:
x = 37 :1
*p = 37, x = 37 :3
*p = 58, x = 58 :5
:6006BFDF4 = p
:7 006BFDF0 = p
:8 58 = *p
:9 006BFDF0 = x
:10 58 = x
. 1 x 2
x .p 3 *p .x p
x *p x .3
4 *p 58 5 *p x
. 6 10 p p *p x
.x p x x p .2
) p p x 6 7 9
. .
(.
:
int
.char .
) .

. (.
:

171

student studentType studentPtr


.studentType student :studentPtr
;studentPtr = &student
3.9 gpa :student
;(*studentPtr) .gpa = 3.9
(*studentPtr) .gpa Dereferencing .
C++ .dereferencing
. C++
> .- > - hyphen : " ".
)( > -:
pointerVariableName -> classMemberName
:
;(*studentPtr) .gpa = 3.9
:
;studentPtr->gpa = 3.9
) ( > -
.dereferencing

.
3-3 .
:3-3
:

172

:main

:
5=x
main 1 cExpPtr classExample
2 cExpObject .classExample
3 cExpObject .cExpPtr .6-3

cExpObject :6-3 cExpPtr &cExpObject = cExpPtr

173

4 cExpPtr setX
.x .7-3

cExpObject :7-3 cExpPtr )cExpPtr -> setX (5


5 cExpPtr print x
.
:
C++
.

. p = 0 p p .
NULL . :
;p= NULL
;p = 0
.
:

.

. .

.

174


.
.

C++ C++

new

delete .
New
.delete
C++ new delete .
new :
new:
;New dataType
;]New dataType [intExp

//
//

intExp . new
)( .
.
:
;*p

int

;*q

char

;x

int

:
;p = &x
x .p .
:
;p = new int
int
.p .*p
:
;]q = new char [16
16 char .q

175


.new :

p // int
;int *p
name // char
;char *name
str // string
;srting *str
// int
;p = new int
// p
//
; = *p
;] // name = new char [5
// char
// .name
;)" // strcpy(name, "John John ) name(
// string
;str = new string
// str
// " "Sunny Day
;"*str = "Sunny Day
// .str

176

.
delete . delete
:
//

;delete pointer

//

;delete [ ] pointer

:
;delete p
;delete [ ] name
p.name
:

.
. .
.
:
;int *p, *q
:
;p = q
q .p p q .
*p *q .
:
p==q
true p q .
:
p = q
true p q .
.
:

177

4 int double 8
Char 1 . studentType 40.
:
;p++

p=p+1

p 4 p .int :
;q++
;chPtr++
stdPtr 40.
.
.

;p = p + 2
p 8.

.
.
.

.
.
.
:

.

.
.
.

178

.
. .
.
new .
:
;int *p
p .int:
;]p = new int [10
10 int
.p new 10 int
.p
:
;*p = 25
25 :
;p++

// .

;*p = 35
35 .
.
C++ . .
:
;p [0] = 25
;p [1] = 35
25 35 . ] p [0
] p [1 . ] p[i
) .(i + 1 p .
for :

j .int

179

p p
. p
.
:
;]int list [10
list 10 . list

. list list .
list list
. list
. P int :
;p = list
list .p
.p
list
. list .
:4-3

. :

1 intList int 2 arraySize


.int 3 4
.arraySize 6
arraySize .intList

180

intList .
intList intList .
:
.
.
)&( .
& .
)*( )&( .
: & *
C++ *
& . :

p q . p q
.
:
C++ . :

.int
:
" "
) ( .

181

. .
.
:
;int *p
;p = new int
p int int
.p 8-3 .

:8-3 p .
) .(int p
. :
;*p = 87
87 .p 9-3 .

:9-3 p 87 .
:
;int *first
;int *second
;]first = new int[10
first second .int
10 .first

.10-3

:10-3 first .
.first
.11-3

182

:11-3 first .
:
//Line A

;second = first

first .second first second


.12-3

first :12-3 second .second = first


A first .
first second . list1list2
list1 list2 list1 = list2
. .
.
:
;delete [ ] second
.second
.13-3

first :13-3 second ;delete [] second


first second :
;delete [ ] second
first .
first .

183

.
.12-3
;) second = first
:(A

10 int
.second first
.second .14-3

:14-3 first second .


first second . second
.first .
14-3

.12-3


.
: :

.
.
:

184

) :(15-3
;pointerDataClass objectOne
;pointerDataClass objectTwo

:15-3 objectOneobjectTwo
:
objectOne .p p
. objectOne .objectOne
p
.delete p delete

. " " . p
p objectOne .16-3

:16-3 objectOne.

185

)
.(1 objectOne
.p
. pointerDataClass:
{
;Delete [ ] p
}
.
pointerDataClass .

.p

p . p
)_ p(
.
.
:
.
objectOne objectTwo .17-3

186

:17-3 objectOne.objectTwo
.
:
;objectTwo = objectOne
objectOne .objectTwo objectOne.x
objectTwo.x objectOne.lenP objectTwo.lenP
objectOne.p .objectTwo.p p
. objectTwo.p objectOne.p
.18-3

:18-3 objectOne ObjectTwo


objectTwo = ObjectOne
objectTwo.p
objevtOne.p . pointerDataClass
p
pointerDataClass . .
C++
.
objectOne objectTwo
.19-3

187

:19-3 objectOne.objectTwo
:
.
)=( :
) (:
;)&const className& operator = (const className
:

=:
.
const .
.
:
;x = x
x x .
.
= . .
if =:

:
;x = x
:
;)x.operator = (x
188

= x this =
.x x =
rightObject .x :
this 1 = &rightObject
this x &rightObject x . false
.if
.
; x = y = z .
.
:5-3
:

cAssignmentOprOverload:

189

190

. 1
2 ) list ( .
) list ( . 4
5 maxSize length of otherList maxSize length
of otherList . ) otherList (
6 10 otherList .list
otherList list .
8 .
13 = .

.cAssignmentOprOverload
:
.
:
;)pointerDataClass objectThree (objectOne
objectThree .objectOne
objectOne .objectThree
. )
( .
20-3 pointerDataClass )
objectOne (.

:20-3 objectOne.objectThree
191


. .
.
pointerDataClass .p
objectOne .21-3

:21-3 .objectOne
:
;)void destroyList (pointerDataClass paramObject
destroyList .paramObject :
;)destroyList (objectOne
objectOne .destroyList paramObject
objectOne
.paramObject paramObject.p ObjectOne.p
.22-3

192

:22-3 objectOne paramObject


.
objectOne paramObject
. paramObject
.
:

.

.

.
.

. pointerDataClass
pointerDataClass 6-3
.
) (:
.
.
.
pointerDataClass
objectOne.p objectThree.p .

objectOne.p paramObject.p
.23-3

193

:23-3 objectOne paramObject .


destroyList paramObject
paramObject .paramObject
.objectOne
:
;)className ( const className& otherObject
6-3 .
:6-3
:

pointerDataClass :

194

195

.pointerDataClass
:
.1 .
.2 .
.3 .
newString .
newString
.
newString ] [ . ] [
. newString ] [
.newString
)( )] [(:
] [ .
] [ .
] [ :
;)Type& operator [ ] (int index
] [ :
;const Type& operator [ ] (int index) const
196

Type .
classTest . classTest
] [ :

Type .
] [ classTest:

:newstring :
:C++
C-string .
C-strings .
C-string .

197

.C
.
cstring
.
C++ .
C++ .

.
. .newString
.newString 24-3 .

198

:24-3 .newString
newString :
.
.newString
cassert .assert assert cassert
.

199

200

201

:
;isObject >> setw (81)>>temp
>> . temp 81
.80 setw ) (
80 .temp
.
.newString
.newString
.newString
:
;newString str
:
;"str = "Hello there
:
;)"Str.operator= ("Hello there
newString
" "Hello there .
newString .str

202


.newString
C++ .newString

203

: .
.Sunny Warm ***### :1
Sunny :3 .Warm
:6 7 <--

123456789

:8 123456789 = s1
s3 = Birth Day, s4 = Birth Day :10
:12 123456789 = s3
:15 s3 = 1t3456789
:17 s3 = 1tw456789
:19 s3 = 1tw45g789
) :(9
;"S4 = s3 ="Birth Day

= s3

" "Birth Day .s4 = s3 11 s1 s3 .


14 19 ] [
.
:
""
.
. :
: .
.
:
.1 . .
.2 .
.3 .
.4 .
.5 .
.6 .
.7 .

204

.8 .
.9 .
.10 .
.11 .
.

.
.
. C++
.
.
:
.
) (.
)
(.
length maxsize
. length maxsize
.int
int
.double .string
) studentType
( .
.

.
.
.
.

205


.
. .

. arrayListType
:

>template<class elemType
class arrayListType
}
206

:
&>const arrayListType<elemType
;)&>operator = (const arrayListType<elemType
// .
;) ( bool isEmpty
// .
// : true
// .False
;) ( bool isFull
// .
// : true
// .False
;) ( int listSize
// .
// : .
;) ( int maxListSize
// .
// : .maxSize
;void print ( ) const
// .
// :
// .
;)bool isItemAtEqual (int location, const elemType& item
//
// .
// : true
// .false
;)void insertAt (int location, const elemType& insertItem
//
// .
// .

07

208

// :
list[location] = insertItem;, and length++; //
//
// .
)void insertEnd (const elemType& insertItem
// .
// insertItem .
// list[length] = insertItem;, and length++; :
// .
;)void removeAt (int location
// .
// : .1
// .
;)void retrieveAt (int location, elemType& retItem
// .
// retItem = list [location] :
// .
;)void replaceAt (int location, const elemType& repItem
// .
// .repItem
// repItem = list [location] :
// .
;) ( void clearList
// .
// .
// : = .
;)int seqSearch (const elemType7 item
// .
// :
// .1-

209

;)void insert (const elemType& insertItem


// insertItem .
//
// .
// list[length] = insertItem;, and length++; :
//
// .
;)void remove (const elemType& removeitem
// . removeItem
210

// .
// : removeItem
// .
;)arrayListType (int size = 100
// .
// .100
// :
Length = 0; maxSize = size
;)arrayListType (const arrayListType<elemType>& otherList
// .
;) ( -arrayListType
// .
:
// .
;elemType *list
// .
;int length
// .
;int maxSize
{
25-3 .arrayListType

:25-3 .arrayListType

211

arrayListType .
. .
length length
.maxSize isEmpty isFull :

length .
maxSize maxSize
. listSize maxListSize:

isEmpty isFull listSize maxListSize


. ).O(1
print .
.

212

print . for
. 100 for 100 .
.n print ).O(n
isItemAt .

isItemAtEqual .
).O(1
insertAt .
.
.
. 26-3 .

:26-3 .
6 .6
.7 6
] .list [6
3 ] list [3] list [4] list [5
. ] list [5 ] list [6]list [4
] list[5] list [3 ] list [4 . list
].[3
.
.
insertAt :

213

insertAt loop .
loop .
)O(n
.
insertEnd .insertAt
insertEnd . :

insertEnd
).O(1
removeAt .inserAt removeAt
.

214

.1

. .27-3

:27-3 .
6 .6
.5 3
] list [4 ] list [3] list [5 ] list [4 .
removeAt:

insertAt removeAt ).O(n


retrieveAt .
.

215

replaceAt :

clearList . length
length
. :

.
.
. 100
. :

216

retrievAt replaceAt clearList


).O(1
:
)(
.

. :

:

:arrayListType

print ).O(n
217

:
.
.28-3

:28-3 .
27 . :
27 ] list [0 27 .35 list [0] 27 27
]) list [1 12 ( . list [1] 27
27 27 ] .list [2 ] list [2 27
.
.10 ] .list [0
10 .
.

"") . (.

"".
.list
:

218

) ( insert
.remove insert
. remove
.
9 seqSearch ).O(n
:
insert .
.
seqSearch .

.1 .
:

219

insert seqSearch insertItem


. seqSearch ) O(n insert
).O(n
:
remove . .
seqSearch
.
.1
seqSearch .
seqSearch removeAt .
remove:

remove seqSearch removeAt .


) O(n remove ).O(n
:
:
220

isEmpty

)O(1
)O(1

listSize

)O(1

maxListSize

)O(1

isFull

********** print
********** isItemAtEqual
insertAt
insertEnd
removeAt
retrieveAt
replaceAt
clearList
constructor
destructor
copy constructor

seqSearch
insert
remove
arrayListType
.
.

221

222

: .
:5 .
:6 79 12 56 78 23 :
:11 79 12 56 78 23 :
:14 56 :
:17 56 79 12 78 23 :
:21 .
:22 5hello sunny warm winter summer :
:27 :
hello sunny warm winter summer
:30 hello :
:33 hello :

223

sunny warm winter summer


:37 7 :
:40 .
:41 7 34 89 12 10 77 67 23 :
:46 34 89 12 10 77 67 23 :
. 1 intList
.arrayListType List intList 100
.int 2 stringList .arrayListType
stringList intList 100 )
( .newString 6 5
. 8 . 9
inserAt intList .intList 12
print intList .intList 14
intList 15
. 16 remove
intList .intList
21 35 5 .19
.
37
38 .intListSize 39 intList2
arrayListType List intListType
.intListSize
. .

: :
) p(x
:

) ( n .

224

) p(x . ) p(x
) p(x .

n ) p(x

. ) p(x
.x

.
. :

) p(x 2 ) q(x .1 :

polynomialType
.
:
.1 .
.2 .
.3 .
.4 .
.
12 .
: ) p(x
.n 0 .n + 1 a1 x1
.29-3

225

] .list [i

:29-3 )p(x
29-3 ) p(x n n + 1
) .p(x :

) p(x .30-3

:30-3 ) p(x 8.
:

) q(x .31-3

:31-3 ) q(x 5.
+ .- :

226

) p(x) q(x ) p(x) q(x .


) p(x) + q(x ) p(x) q(x ).max(n, m
) p(x) * q(x ) p(x) q(x :

n + m ..... 2 1 0 = k :

. :

2 .

+-

* . ) (
.
<< >>.

arrayListType .
polynomialType arrayListType
.
.

227

) 19 (
.polynomialType
) p(x 3 p polynomialType
.4 :p
;)polynomialType p(4
length
.arrayListType
.
length .

) ( .

228

) p(x n ) q(x .m n = m
+ ) p(x) .q(x n > m
m ) p(x ) .q(x )p(x
) p(x) .q(x n < m
n ) q(x ) p(x ) q(x
. .+
:

229

* .
10 . polynomialType:

230

231

:
7 :
0 : x^0
1 : x^1
4 : x^2
0 : x^3
0 : x^4
0 : x^5
0 : x^6
6 : x^7
1x^1 + 4x^2 + 6x^7 :p(x) :5
468855 :p(5) :6
3 :
1 : x^0
2 : x^1
0 : x^2
3 : x^3
1 + 2x^1 + 3x^3 :q(x) :8
1 + 3x^1 + 4x^2 + 3x^3 + 6x^7 :p(x) + q(x) :10
-1 - 1x^1 + 4x^2 - 3x^3 + 6x^7 :p(x) - q(x) :11
:
.1 .
.2 C++ .
232

.3 )*( .
:
;int *p
;char *ch
p ch . P int
ch .char p int ch
.char
.4 C++ & .
.5 . p int
num int :
;p = &num
p .num
.6 * .
.7
* . p int :
;*p = 25
p .25
.8 > -
.
.9 NULL
.
.10 .
.11 )(++
) (--
.
.12 .

.
.
.13 ) .
(.

233

.14 .
.15 .
.16 new .
.17 delete .
.18 C++ new delete .
.19 new :
.
.20 p int :
;p = new int
int
.p
.21 delete :
.
.22 p int :
;Delete p
.p
.23
.
.24 new
. p int :
;]p = new int [10
10 int p
p .
.25 .
p 10 . ] p [0 p
] [1 . ] p [i ) (i + 1
.
.26 .
.27 p :
;delete [] ] p
p .p

234

.28
) . " "(.
.29 ) .
" "(.
.30
.
.31
.
.32
.
.33 .
.34 :




.

:
.1 :
. C++ .
. C++ .pointer
. ; delete p .p
. ; delete p .p
. :
;]int list [10
int *p
:
;p = list

235

.C++
. :
;int *p
:
;]p = new int [50
50 int p
.
. .
. p p = p * 2 .C++
.2 :
;int x
;int *p
;int *q
. .
p = q; .
*p = 56; .
p = x; .
*p = *q; .
q = &x .
*p = q; .
.3 C++

.4 C++

236

.5 :
;int num = 6
;int *p = &num
num
.

;p++

(*p) ++; .
num++; .
(*num) ++; .
.6

.7

237

.8

.9

238

.10 .
.11

.12

239

.13
.14 .
.15 .
.16 . + newString .
s1 " "Hello s2 " "there

s1 = s3

s2 + " "Hello there s3 s3


.newString
. = + newString : s1
" "Hello s2 " ."there :
;s1 += s2
" "Hello there s1 s1 s2 .newString
.17
arrayListType<int> intList (100); .
arrayListType<string > stringList (1000); .
arrayListType<double > salesList (-10); .
.18 polynomialType
.


.1 cAssignmentOprOverload .5-3
.2 pointerDataClass .3-6
.3 newString :
. + = + .
. length .
. .
. .newString
.4

. newString
3 .
. newString .
. .newString

240

.5 removeAt arrayListType
.
.

. removeAt
.
.6 remove arrayListType .
removeAll arrayListType .
removeAll .
.7 min arrayListType
min .
.8 max arrayListType
max .
.9 + - .polynomialType
.
.
.10 * ) ( polynomialType
*.
n

.11
) ( n .
) p'(x
) p(x 0

) p(x

)= p'(x
=

) .p'(x ~

polynomialType ~ .
.12 polynomialType
.

.


+ -*

) ( .
.

241

.13
.
500.
. addressType
.
.
. extPersonType ) personType
6-1 ( ) dateType
2 (2 .addressType
.
. ) (
. .
. addressBookType arrayListType
addressBookType
.extPersonType addressBookType
500 .
addressBookType :
)(i

)(ii

)(iii

) ( .

)(iv

)( v

)(vi

).14 ( C++ .
.
C++ . safeArray

. safeArray

242

.int
. :
;)safeArray list (2, 13
;)safeArray yourList (-5, 9
list 11 int ]list [2
] list [3 yourList .list [12] ....... 15
int ] yourList [-5] yourList [-4 .......] list [0 ........
].yourList [8
.15 14 int . safeArray
.
.16
.
. A 5 6 A 6 5

. .

m n

A i j

. A B :

A (A * B) B A .B
A m n B n t
m t

matrixType

100

100 + -*
<<
.

243


:
.
.
********************
**********
******************
2 . ) (
. 3 arrayListType
. 5 7 8
: . 5
.
. 7
8 .
.
C++ .
) ( .

. 13


.

244

:


.

.
. .

.
5 .
) .(7
) .(8
.
:
.
.
.
.
.
.13
:

:
) (.
.
.
.
13 7.8

245

:
. :
vector
deque
list
vector .
vector
. vector
.
.
vector .deque 5 .list
vector :
vector .
vector .
.
.
vector ) .vector
( . vector .vector
vector :
>#include <vector
vector vector
. :
;vector<int> intList
intList vector .int :
;vector<string > stringList
stringList vector .string

246

:vector
vector . vector
. 1-4 vector .
:1-4 .vector

; vector<elementType> vecList vecList )


.
vector<elementType> vecList

vecList vecList

;) (otherVecList otherVecList

vector

vecList otherVecList .
;) vector<elementType> vecList (size vecList size vecList
.
;) vector<elementType> vecList (n, elem vecList n
n .elem
;) vector<elementType> vecList (begin, end vecList
) (
.beginend-1

:1-4
. intList vector :int
;vector<int> intList
. intList vector 10 .int
intList :
vector<int> intList
. intList vector 5 .int
intList :

intList .intArray:
}intList = {2, 4, 6, 8, 10
vector
.vector :
247

.
.
.vector
vector
.2-4
:2-4 :vector

vecList.at (index), index


;] vecList [index .index
;) ( vecList.front ) (
;) ( vecList.back ) (

2-4 vector ) .
vector
(.
:2-4
intList vector 5 :int
;)vector<int> intList (5
:intList

for .intList
vector .vector vecList
.vector vecList
.3-4 vector .
3-4 .

248

:3-4 :vector

) ( vecList.clear
) vecList.erase (position position
) vecList.erase (beg, end beg end-1
) vecList.insert (position, elem elem
position .
) vecList.insert (position, n, elem n elem
position
) vecList.insert (position, beg, end beg
end-1 vecList
position
) vecList.push_back (elem elem vecList
) ( vecList.pop_back
) vecList.resize (num .num ) (
.
) vecList.resize (num, elem .num ) (
.

3-4 position .
.
.
vector .
""
.
push_back . -4
2 intList .5 5
intList . 5

249

.push_back 2-4
4 .
vector
vector . .3-4
push_back 3-4 5-4
.vector
:3-4
intList vector :
;Vector<int> intList
intList push_back :
;)intList.push_back (34
;)intList.push_back (55
intList 2} .intList = {34, 55
resize intList .
push_back
.
:vector
vector
vector ) .
( . .vector
)
( . . vector
insert .vector
insert . erase
.
.vector

250

vector typedef .
vector .typedef :
;vector<int>: : iterator intVecIter
intVecIter vector .int
typedef vector )(vector
.typedef
intVecIter Vector .int
:
++intVecIter
intVecIter :
*intVecIter
.
.3
* .
vector
.vector :

1 intList vector int 2


intVecIter vector .int
begin) end (:
begin .end begin
end . .
:
;) ( intVecIter = intList.begin
intVecIter />
for intList :

251

:4-4
:

2 vecList :

4 intVecIter vecList
5 intVecIter vecList 6 22
.intVecIter
6:
}vecList = {1, 22, 3, 5, 7, 9, 11, 13
.
vector
.

4-4

) . vecCont .(vector
:4-4 :vector

) ( vecCont.capacity vecCont
*********
) ( vecCont.empty true vecCont .false
) ( vecCont.size .vecCont
) ( vecCont.maxsize .vecCont

5-4 vector
.vector
:5-4
>#include <iostream

252

>#include <vector
:std

:
:7 35 28 75 13 :
:13 70 56 150 26 :
:18 70 56 150 26 :

253

:26 70 56 88 150 26 :
1 ) vector (Vector intList .int
2 i int 3 6 push_back
35 28 75 13 .intList

8 9

for ] [ .intList
7 7 10 .
11 12 for intList
14 15 .intList 13
13 16 .
17 listIt vector vector
.int listIt 19 20 .intList
22 listIt .intList 23
24 listIt listIt .intList
25 88 intList .listIt listIt
) 2 (intList 88 2
intList 88 .intList 27 28
intList.
:
.vector .

.
.

.
. 5-4
.
ct ct1 ct2 . 5-4
.
:5-4 :

254

) ( ct.empty

true ct false

) ( ct.size

int ct

) ( ct.max_size

.ct

:5-4 )(

)c1.swap (ct2

ct1ct2

) ( ct.begin

.ct

) ( ct.end

.ct

) ( ct.rbegin

ct
ct.

) ( ct.rend

ct

)ct.insert (position, elem

elem ct position
position

)ct.erase (begin, end

1- .ct

) ( ct.clear

. ct.


;ct1 = ct2

ct2 .ct1 .

ct1 = = ct2

true ct1 ct2 .false

ct1 ! = ct2

true ct1 ct2 .false

255

:

6-4
vector deque) .list seqCont (.
:6-4 .

)seqCont.insert (position, elem


)seqCont.insert (position, n, elem
)seqCont.insert (position, beg, end
)seqCont.push_back (elem
) ( seqCont.pop_back
)seqCont.erase (position
)seqCont.erase (beg, end
) ( seqCont.clear
)seqCont.resize (num
)seqCont.resixe (num, elem

elem seqCont
.position .
n elem seqCont
.position
1-
seqCont .position
elem seqCont .
.
.position
.1-
.
.num ) (
.
.num ) (
.elem

:
5-4 for .vector
.copy copy
.
.
copy
.13

copy
. vector vector
vector .copy copy:

256

first1 last .
first2 . first1 last
first2 . last-1......first1
.
copy .algorithm copy
:
>#include <algorithm
copy . :

1 intArray :

2 vector .int
intArray
. intArray intArray + 1
.
:
intArray
intArray ) intArray + 9 1 (intArray + 8
intArray ) .vecList first1 intArray last intArray +
9 first2 ) ( .(vecList.begin :3

first1 intArray + 1 first1


intArray last .intArray + 9 first1 intArray first2

257

.intArray
.
:5
intArray .
vecList .4 :

) rbegin (
. vecList.rbegin ( ) + 2
.vecList ) rend (
. vecList .
7 :vecList
6-4 .C++ 6-4
ostream
copy .
ostream :copy
for begin
for set . copy
. ostream )
ostream ( . ostream
.
ostream :int
ostream_iterator<int> screen (cout, " "); // Line A
ostream screen .int screen :
cout . screen cout
.
:

258

copy (intArray, intArray + 9, screen):


intArray .
:
copy (vecList.begin ( ), vecList.end ( ), screen):
vecList .
copy
.ostream ostream
A .ostream
ostream .copy
) (:
copy (vecList.begin ( ), vecList.end ( ), screen):
:
;) ( copy (vecList.begin ( ), vecList.end
;))" " ostream_iterator<int> (cout,
:
;) ( copy (vecList.begin ( ), vecList.end
;))" " ostream_iterator<int> (cout,
vecList .
6-4 copy ostream .

259

:6-4

:
75 29 98 36 40 3 8 6 5 :intArray :4
75 29 98 36 40 3 8 6 5 :vecList :8
:12 :intArray
75 75 29 98 36 40 3 8 6
:16 :vecList
98 36 40 3 8 6 5 6 5

260

:deque :
.deque deque .
deque .
deque . .

.
deque .deque deque
deque .deque
deque :
>#include <deque
deque deque
.7-4
:7-4 deque

; deque<elementType> deq Deque )


.(deque
;) Deque<elementType> deq(otherDeq deque deq
.otherDeq deq otherDeq .

:7-4 ) deque(:

;) deque<elementType> deq (size deque size deq


.
;) deque<elementType> deq (n, elem deque deq n
deq n .elem
;) deque<elementType> deq (begin, end deque deq
) (
... .1-

) (6-4 8-4
deque
. . deq
.deque

261

:8 -4 :deque

)deq.assign (n, elem


)deq.assign (beg, end
)deq.push_front (elem
) ( deq.pop_front
)deq.at (index
]deq [index
) ( deq.front
) ( deq.back

n .elem
....1-
elem .deq
.deq
.index
.index
) (.
) (.

7-4 deque .
:7-4

262

263

:
35 28 75 13 :intDeq :7
:12 :intDeq
100 35 28 75 13 0
:17 100 35 28 75 :intDeq
:22 28 75 :intDeq
:29 444 28 444 75 :intDeq
:33 45 45 45 :intDeq
:38 :intDeq
999- 45 45 10 1 deque intDeq int
intDeq .int 2 screen ostream
. 3 6 push_back
25 28 75 13 .intDeq 8 .intDeq
7 7
9 .
10 intDeq 11 100
.intDeq 13 intDeq .

264

15 16 pop_front intDeq
18 intDeq . 20 21
pop_back intDeq 23 intDeq .
25 deqIt deque deque
.int 26 deqIt .intDeq
27 deqIt .intDeq 28 444
intDeq .deqIt 30 .intDeq
32 45 .IntDeq 32
intDeq intDeq .45
34 . 33
33 35 .
.
:
5-4 7-4 .
.
) (.
.
) ++ ( * ) ( .
cntIte .:
;++cntItr
.cntItr
:
:
.
.
.
.
.
.

265

:
.
.
inputIterator . 9-4
.inputIterator
:9-4 :

******* *******
inputIterator->member .
++inputIterator ) (
inputIterator++ ) (
inputIt1 = = inputIt2 true .false
******** true .false

:

. .
outputIterator . 10-4
.outputIterator
:10-4 :

; *outputIterator *** value .outputIterator


++outputIterator ) (
outputIterator++ ) (

.
.

266

:
.
forwardIteratorforwardIterator . 11-4
.forwardIterator
:11-4 :

*forwardIterator .forwardIterator
forwardIterator -> member .
++forwardIterator ) (.
forwardIterator++ ) (.
forwardIt1 == forwardIt2 true .false
forwardIt1 += forwardIt2 true .false
forwardIt1 = forwardIt2.


.
:
.
biDirectionalIterator .
) (11-4

.biDirectionalIterator

12-4

.
:12-4 :

--biDirectionalIterator ) (
biDirectionalIterator-- ) (

vector deque listset


multiset map.multimap

267

:
.
vector dequestring
. . ) -4
11 (12-4 ) . rAccessIterator
(.
:13-4 :

]rAccessIterator [n
rAccessIterator += n
rAccessIterator -= n
rAccessIterator + n
n + rAccessIterator
rAccessIterator - n
rAccessIt1 rAccessIt2
rAccessIt1 < rAccessIt2
rAccessIt1 <= rAccessIt2
rAccessIt1 > rAccessIt2
rAccessIt1 >= rAccessIt2

.n
rAccessIterator 0 =< n 0 > n
rAccessIterator 0 =< n 0 > n
.n
.n
.n
rAccessIt1.rAccessIt2
true rAccessIt1 rAccessIt2 .false
true rAccessIt1 rAccessIt2
.false
true rAccessIt1 rAccessIt2 .false
true rAccessIt1 rAccessIt2
.false

1-4 .

268

:1-4 .
.
typedef iterator
) ( typedef
.typedef :
;Vector<int> : : iterator intVecIter
intVecIter vector .int
intVecIter > vector<int
> vector<double > vector<string .deque
typedef ) ( vector
.typedef
typedef const_iterator
*
. const
.

typedefm,

const_iterator.
:
;vector<int>: : const_iterator intConstVecIt
intConstVecIt vector .int
intConstVecIt vector
vector >.vector<int
const_iterator .
typedef reverse_iterator
.typedef reverse_iterator
.
typedef const_reverse_iterator
.
const .
typedefs typedefs
. 14-4.
typedefs :14-4 :

269

typedef

diferrence_type
pointer .
reference .
const reference . .
size_type .
.List
value_type

:
: istream
.ostream .
istream
istream_iterator . istream:
;)&istream_iterator <Type> isIdentifier (istream
Type
. isIdentifier istream
cin istream .ifstream
ostream_iterator
ostream .
.
ostream_iterator
ostream:
;)&ostream_iterator <Type> osIdentifier (ostream
:
;)ostream_iterator <Type> osIdentifier (ostream&, char* deLimit

270

Type
. osIdentifier ostream
cout ostream .ofstream
ostream ) (delimit
.
: :
.

.
.
.
.
.

. :





.
.
.


271

.
.
.
. .
:

345 .
: 890238
4 . MTH345
4 .
:

: .
890238 :
4 :

CSC478

HIS356

MTH345

PHY357

272

13 :
3.54 :

)( )( )(
)( )( .
: .
ch4_GradeData.txt
)(.
: : .
:
.
. .
: .
:
.
.
:
.1 .
.2 .
.3 .
.4 .
.5 .
) :(2-4

courseType
}
273

:
Void setCourseInfo (string cName, string cNo,
;)Char grade, int credits
// .
// .
// : = cName = cNo
= grade = credits

274

;)void print (bool isGrade


// .
//
// . isGrade
// .
;)void print (ofStream& outp, bool isGrade
//
// .
// isGrade
// .
;) ( int getCredits
// .
// : .courseCredits
;)void getCourseNumber (string& cNo
// .
// = cNo : .
;) ( char getGrade
// .
// : .courseGrade
// .

courseType (string cName = " ", string cNo = " ",


;)char grade = '*', int credits = 0
//
// .
// : = cName = cNo

275

= grade = credits

:
;string courseName

// .

;string courseNo

// .

;char courseGrade

// .

;int courseCredits

// .

:2-4 .courseType
.courseType
setCourseInfo :

276

print
isGrade
. )
( . .left
. :
.1 .left
.2 .
.3 .
.4 .left
.5 .
.6 isGrade

.
print:

print .
print.
:

277

. courseType
. :
* .
. :

278

.
:
.
.
.
personType .
. studentType
personType .courseType
.
studentType:
.1 .
.2 .
.3 .
.4 .
.5 .
.6
.
studentType .
) 3-4 (.

279

:public personType :studentType


}
:
void setInfo (string fname, string 1Name, int ID,
bool isTPaid,
vector<courseType> courses);
. //
280

// : .
;)void print (double tuitionRate
// .
;)void print (ofstream& out, double tuitionRate
// .
// .out
;) ( studentType
//
// : .
;) ( int getHoursEnrolled
// .
// :
// .
;) ( double getGpa
// .
// : .
;)double billingAmount (double tuititonRate
// .
// : .
:
;int sID
;int numberOfCourses
;Bool isTuitionPaid

// .
// .
// .

281

:3-4 studentType .
.studentType
setInfo .
studentType personType
. setName
personType .
coursesEnrolled sort
.
sort Vector courses Enrolled
.coursesEnrolled
coursesEnrolled . begin vector
vector end .
) ( coursesEnrolled.begin coursesEnrolled
)

coursesEnrolled.end . =<

courseType
.coursesEnrolled :coursesEnrolled
;)) ( sort (coursesEnrolled. begin ( ), coursesEnrolled.end
setInfo:

.
coursesEnrolled vector vector
.coursesEnrolled

282

print
.

. :
.1 .
.2 .
.3 .
.4 : .
.5 .
.6 .
.7
fixed showpoint
.
.8 tutitionPaid

.

283

print .
print . personType
getName personType
. .
print :

284

getHoursEnrolled .
.
.
.courseType
getCredits courseType .
:
285

billingAmount
. :

getGpa .

. :

:
courseType studentType
.
286

print studentType
.
.

. :
.1 .
.2 .
.3 .
.4 .
.5 .
.6 .
.7 .
: vector studentList
.studentType .

. :

;Vector<studentType> studentList
;double tuitionRate
;ifstream infile
;ofstream outfile

// .
// .
// .
// .

Main getStudentData
printGradeReports . .
:getStudentData :
vector .studentList :
:
.1 .isPaid
.2 isPaid " "Y isTutitionPaid true

287

isTutitionPaid .false
.3 .
.4 vector .
.5 :
. .
. .courseType
. vector
.
.6 .studentType
.7 .
. getStudentData:

//
;stringfName
;string lName
;int Id
;int noOfCourses
;char isPaid
;bool isTuitionPaid
;string cName
;string cNo
;int credits

//
// .
// .
//
// / .
// true / false
//
// .
// .

288

;char grade
;int i
;vector<courseType> courses

//
//
// .

:printGradeReports .
print studentType .

printGradeReports:

289

290

291

292

// getStudentData.
// printGradeReports.
:
:
890238 :
4 :

CSC478

HIS356

MTH345

PHY357

13 :
3.54 :
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- :
798324 :
5 :

293

BIO234

***

CHM256

***

ENG378

***

MTH346

***

PHL534

***

17 :
*** *** .
5865.00 :.
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- :
746333 :
6 :


BUS128

CHM348

CSC201

ENG328

HIS101

MTH137

19 :
3.16 :
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- :
345
890238 4
4 MTH345
3 PHY357

3 CSC478

3
HIS356
798324 5
3 ENG378

294

3 PHL534
4 CHM256
4 BIO234
3 MTH346
6

746333
3 HIS101
3 ENG328
3 MTH137
4 CHM348
3 CSC201

3
BUS128


.1 .
.2 : .
.3 .
.4 .
.5 .
.6 .
.7 vector deque.list
.8 vector .
.9
.
.10 vector .vector
.11 vector insert .push_back
.12 vector pop_backerase
.clear
.13 vector typedef
.vector
.14
empty size max_size swapbegin
end rbegin rend Insert erase clear .
.15 begin .
295

.16 end .
.17 14
insert push_back pop_back eraseclear
.resize
.18 copy .
.19 ostream copy .
.20 ostream
.
.21 deque
.
.22 deque .
.23 deque .deque
.24
deque assign push_front pop_frontat
] [ front.back
.25
.
.26 .
.27 .
.28
.
.29
.
.30 list setmultiset
map.multimap
.31
.
.32 vectordeque
string.

296


.1
.2
.3 vector 50 .
.4 :vector
;}'char vowels [5] = {'a', 'e', 'i', 'o', 'u
.5 screen ostream
int .vector
.6 :
;vector<int> intVector
} intVector = {5, 7, 9, 11, 13 screen
ostream .vector

;)copy (vecList.begin ( ), vecList.end ( ), screen


.7

.8 ) screen ostream
(.int

297

.9 ) screen ostream
(.int

.10 ) screen ostream


(.int

.11 ) screen ostream


(.double

.12 ) screen ostream


(.int

298

vector vecList .13


vecList = {12, 16, 8, 23, 40, 6, 18, 9, 75}
: vecList
copy (vecList.begin ( ) + 2, vecList.end ( ), vecList.begin ( ));
vector vecList . .14
vecList = {12, 16, 8, 23, 40, 6, 18, 9, 75}
: vecList
copy (vecList.rbegin ( ) +3, vecList.rend ( ), vecList.rbegin ( ));
.15

299


.1
.
.
. :

5000

25.91

4000

20.72

6000

31.09

2500

12.95

1800

9.33

19300

:
.2
) :(50
. .
. .
. .
.3 vector .
. vector
push_back .vector
.4 reverseVector vector :

// .vector
// : = ).(5 2 8 4

300

// = )8 2 5 .(4
.reverseVector object
push_back .vector
.5 seqSearch vector
:

//
// .1-
.seqSearch push_back
.vector
.6 6
.vector
.7 13
.vector
) .8 ( .
.
.
10 .
.
:
Symbol openingPrice closingPrice todayHigh todayLow prevClose
volume
:

301

MSMT 112.50
115.75 116.50 111.75
113.50 .6723823
:
********* *********
*********

ABC

*********

132.00

125.00

120.50

%8.67

10000

AOLK

80.00

75.00

82.00

74.00

83.00

%9.64-

5000

CSCO

102.00 100.00

105.00

98.00

101.00

%0.99

72.00

67.00

75.00

%5.33-

145.00 140.00 120.00

140.00

115.00

%21.74

IBD
MSET

130.95 123.45

68.00

71.00

25000
15000
30920

9628300.00 :
**-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- . ) (
) ( .
) . ( .
.stockType
.

/ . .
.
:
.1 .
.2 .
.3 .
.4 / .
.5 .
.1. .
.

302

.2. << .
.3. >> .
infile ifstream
.infile myStock . :
;infile>>myStock
) .myStock
.(myStock
. stockType
.
.stockListType .vector
vector .stockType
. stockType:

. .

303


5

:
**************
*************
*************
***************
.
.

. )
(9 .

.
.
.
.
) ( .
.
contiguous
.
**** .

304

:
. ) (
. :
) ( .
. 1-5
.

:1-5
:
.
2-5 :

:2-5
.NULL
.
1200
.1575 .3-5

:3-5 .
1200 45
1575 . .
2-5 3-5
.int .struct

305

.
3-5 4-5 5-5 6-5 .
.
.struct

.
) :(int

head .nodeType
;nodeType *head
: :

.
.4-5

:4-5 .
.head
) Info ( ) link ( .
info .int
2000 2800
1500 .3600 2000 head link
2800 link 1500 .

306

link NULL
. .
1-5 head .4-5
:1-5 head .4-5

head

2000

head->info

17

head->link

2800

head->link->info

92

****
2000 = head 17 = 2000
****
2800 = head->link 2800 .92

current .head :
;current = head
head .current .5-5

:5-5 .current = head


2-5 current .5-5
:2-5 current .5-5

1000

current
current->info

17

current->link

2800
92

current->link->info

:
;current = current->link
current->link 2800 .current
current ) .

307

( . -5
.6

:6-5 ;current = current->link


3-5 current 2-5 current
.
:3-5 current .6-5

1000

current
current->info

17

current->link

2800
92

current->link->info

4-5 .6-5
:4-5 .6-5

head->link->link

1500

head->link->link->info

63

head->link->link->link

3600

head->link->link->link->info
current->link->link

45
3600

current ->link->link->info

45

current ->link->link->link

) 0 (NULL

current ->link->link->link->info

.
:
:
.

308

.
.

.
head .NULL
head head
. . head

. head )
( . head )
head
(.
head
. current .head
:

head .
:

:
. .
) .int " "

(.

309

:
.7-5

:7-5 .
p 65 50
.p 50 info :

;newNode = new nodeType

// .

;)assert (newNode !=NULL

//
//

;newNode->infor = 50

// 50

); (newNode = new nodeType


.newNode
. ); (newNode->infor = 50 50
info . . 8 -5

310

:8 -5 newNode 50.
:

); (newNode->link = p->link
.9-5

:9-5 ;newNode->link = p->link


); (p->link = newNode -5
.10

:10-5 ;p->link = newNode


newNode
p .
.

11-5 .

311

:11-5 ; p->link = newNode newNode-


;>link = p->link
11-5 newNode .
. q .info 34
.12-5

:12-5 p.q
newNode p:q

.
:

; p->link = newNode 13-5

:13-5 .p->link = newNode


q .
; newNode->link = q .14-5

312

:14-5 .newNode->link = q
:
.15-5

:15-5 .info 34
info 34 . :
;p->link = p->link->link
16-5 .

:16-5 ;p->link = p->link->link


16-5 info 34 .
. .
:

q = p->link .17-5

:17-5 q = p->link
; p->link = q->link .18 -5

313

:18-5 ;p->link = q->link


; delete q .19 -5

:19-5 ;delete q

.
; delete q q
. q .
q NULL .delete
:
.
.
. : .

. .
:
info-link info .int
:
34 24 8 15 2
:
.
:

314

first . firstlast
.NULL :

first last .NULL


:

// 1 num
// 2 nodeType
//
// newMode
// 3
//
// 4 num
info // newNode
// 5 newNode NULL
// 6 NULL = first
// first last newNode

315

// 7 .

7 // newNode
7 // last .
. first last .NULL
.20-5

:20-5 .
num 1 .2 2
.newNode 3 . 4
2 info newNode 5 NULL link
.newNode .21-5

newNode :21-5 .info 2


first = NULL 6 6 . 22-5 .

:22-5 newNode.

316

1 7 . num 1 .15 2
.newNode 4 15 info newNode
5 NULL link .newNode
23-5

:23-5 newNode .info 15


first NULL 7 7 . 24-5 .

:24-5 newNode .
1 7 . 25-5 .

:25-5 8 24.34

. C++ .
.999-
buildListForward ) ( .

317

:
.

34 24 8 15 2 .26-5

:26-5 .

.last
. first
. :
. first .NULL
:
.1 first .NULL
318

.2 :
-

.newNode

- .newNode
- newNode .first
- .first
C++ :

:
.

.

.
.
:
.1 .
.2 .
319

.3 .
.4 .
.5 .
.6 .
.7 .
.8 .
.9 .
.10 .
.11 .
.
.
.
. buildListForward
buildListBachward
. insertFirst :
insertLast .
first :
last .
.
:

320

321

322

linkedListType
. " "
9.10
copyList
.
.
linkedListType .
) 2 .(3
. .
first NULL isEmptyList
:

:
.
linkedListType :

323

isEmptyList ).O(1
:
destroyList .
.delete
. first
last NULL count . :

;nodeTYpe<Type> *temp
)while (first ! = NULL
;temp = first
;first = first->link
;delete temp
;last = NULL

//
// .
//
// temp
// first
// temp
// last NULL first
// NULL .while

n while n .
destroyList ).O(n
:
initializeList .
.
) ( .

324

destroyList first last NULL


count . :

;) ( destroyList

//
//.

initializeList destroyList ) O(n


initilaizeList ).O(n
:
.
. first
) . first
(.
:

destroyList ).O(n
:
) ( .count
. :

325

:
front :

assert .
.
:
back :

assert .
.
length front back ).O(1
:
search . .true

.
:
.1 .
.
.2
.

326

search:

while search
. n .
while n .
while
i while i .
) .O(n .9
:
inserFirst
.first :
.1 .
.2 .
.3 .
.4 .first
.5 count .1

327

insertFirst:

:
insertLast .insertFirst
.last insertLast :

328

insertFirst insertLast ).O(1


:
deleteNode .
:
:1 .
:2 .
.first
:3 .
.last
:4 .
.
.
count .1 :

) (

}

first) last (
count

}


) Last ( .count
{
{
:
:1 .
.
:2 .

329

: .
.27-5

:27-5 .
.37 . firstlast
NULL count .
.28-5

:28 -5 .
.28 .
first first
17 count .1 29-5 .28

:29 -5 .28
:3 .
) :( )(
. .
3 : .
.30 -5

330

:30 5 37
.37
) .31-5 37 first .last
17 . 17 (.24

:31-5 37
3 : .
.32-5 .54

:32-5 54
54 24 . 54
.last 54 last .24 count
.1 33-5 .

:33-5 .54
:4 . .
.
2 3 4 .
) . 1
(.
.
.

331

. :
.
.last
deleteNode:

332

deleteNode ).O(n
:
copyList .
. :
.1 .newNode
.2 ) ( .newNode
.3 newNode .
copyList:

333

copyList .loop while


. n while
n . copyList ).O(n
:

. first last
.
. destroyList :

:
linkedListType
.
.
) . .(3
.
.copyList copyList
.first first NULL .copyList
:

334

:
linkedListType .
.

destroyList ) .O(n
copyList ) .O(n
).O(n
5-5 .linkedListType
:5-5 .linkedListType

isEmptyList

destroyList
initializaList

length
front
back
search
insertFirst
insertLast
deleteNode
copyList


)O(1
)O(1
)O(n
)O(n
)O(n
)O(1
)O(1
)O(1
)O(n
)O(1
)O(1
)O(n
)O(n
)O(n
)O(n
)O(n

35

linkedListType
:

:
C++

.
:
.1 .
.2 .
.3 .
.4 .
.5 .
.6 .
.7 .
.8 .
.9 .
.10 .

.
.
.linkedListType

.
. 6
.
.

336

orderedLinkedListType

.linkedListType

linkedListType insertFirst insertLast


.
.
. insertFirst insertLast
.
.
" " last .
last NULL first . back
linkedListType Last .
last )
orderedLinkedListType .(8

:
.
" " .
.

337


.
:
.1 .
.
.2
.
.
.

:

.
. current : trailCurrent . current
trailCurrent
current .
. :
:1 .
.
338

:2 .
. .first
count .1
:3 .
.
3 : .
. current NULL .trailCurrent
count .1
3 : .
trailCurrent .current count .1
3 3 ) newNode (:

.
:1 .
.34-5

:34-5 .
27 . 27
NULL first . 35-5
.

:35-5 .27
27 first.count

339

:2 .
.36-5

:36-5 .10
.10 10 10
. .first count .1

37-5

:37-5 .10
:3 .
.
3 : .
.38-5

:38-5 .65
65 . 65
.39-5

340

:39-5 .65
3 : .
.40-5

:40-5 .27
27 . 27 17 38
.17 27
.41-5

:41-5 .27
3
. current.trailCurrent
current .
trailCurrent .current 3
trailCurrent 17 current 38
.traiCurrent 3 65 trailCurrent
54 current .NULL
insertNode :

341

inserNode
. 7
insertNode .

.

342

:

.
. .
insertNode current .trialCurrent
insertNode :
:1 . .
:2 .
.first
:3 . current
trailCurrent
current .
:4 .
count .1 deleteNode:

343

:

orderedLinkedListType ) .
linkedListType .linkedlist.h
//
// orderedLinkedList.h :

344

// search
insertNode // deleteNode.
#endif
:
//

345

: .
:3 999-
999- 29 55 36 82 12 72 34 65 23
:9 82 72 65 55 36 34 29 23 12 :1
:11 82 72 65 55 36 34 29 23 12 :2
:12 36 :
:16 2:
82 72 65 55 34 29 23 12
:
next
.back ) (
) ( . .42-5

:42-5
.
.
:
.1 .
.2 .
.3 .
.4 .
.5 .
.6 .
.7 .
.8 .
.9 .
.10 .
.11 .

346

347

348

.
back next
. . copyList
) . 9
(.
:
first Last
NULL count :

:isEmptyList
true .false
first NULL :

:
.
. :

349

:
.
.destroy initializeList:

:
. :

:
.
. first
.
:

350

.
:

:
search true .false
:

:
front back .
. :

351

:

.

. :
:1 .
:2 .
:3 .
:4 .
1 2 first 3 4 .
count 1 .4
.43-5

:43-5 .20
20 . 20 44-5 .

352

:44-5 .20
44-5 next 15 next
back .20
insertNode:

353

:
) ( .

. ) ( insertNode
. :
:1 .
:2
.first
:3 .
:4 .
count .1 .3
.45-5

:45-5 .17
.17
17 . .46-5

354

:46-5 .17
count 1 .current .47-5

:47-5 .17
deleteNode:

355

doublyLinkedList linkedListType
.
list :
vector deque list
vector deque
. .
) ( .
.
.

356

list .list list


.list list
:
>#include<list
list list
.6-5
:6-5 .list

************
*******
*************
*********

) 5-4 (4 6-4
.
7-5 .list
.
listCont .list
:7-5 .list

n .elem
)listCont.assign (n, elem
... .1-
)listCont.assign (beg, end
.listCont
)listCont.push_front (elem
.listCont
) ( listCont.pop_front
.
) ( listCont.front
.
) ( listCont.back
.elem
)listCont.remove (elem
) oper (elem .true
)listCont.remove_if (oper
********
) ( listCont.unique
********
)listCont.unique (oper
listCont2 listCont1
)listCont.splice (pos, listCont2
pos
listCont2.
) listCont.splice (pos, listCont2, pos2 pos2 listCont2
listCont1 pos
... 1-
)listCont. (pos, listCont2, beg, end
listCont2 listCont1
pos
listCont <
) ( listCont. sort

:7-5 ) list(
357

)listCont.sort (oper
)listCont.merge (listCont2

)listCont.merge (listCont2, oper

) ( listCont.reverse

listCont .oper
listCont1 listCont2 .
listCont2 listCont1
listCont1 listCont2.
listCont1 listCont2
.oper listCont2 listCont1
listCont1
.oper
.listCont

1-5 .
:1-5

358

359

:
58 98 93 15 36 58 58 58 23 :intList1 :12
58 98 93 15 36 58 58 58 23 :intList2 :16
:20
58 98 93 15 36 58 23 :intList1
:24 98 93 58 58 58 36 23 15 :intList2
198 136 25 23 13 :intList3 :32
8- 7- 2- :intList4 :38
:42 intList4 intList3
198 136 25 23 13 8- 7- 2- :intList3
:46 198 136 25 23 13 2- 7- 8- :intList3
:50 intList2 intList3 intList2
198 136 98 93 58 58 58 36 25 23 23 15 13 2- 7- 8- :
:54 intList2
198 136 98 93 58 36 25 23 15 13 2- 7- 8- :
. 3 11
) 58 98 93 15 36 58 58 58 23 ( .intList1
15 intList1 .intList2 intList1intList2
. 19 .
58 . unique .58
58 .intList1

360

23 .intList2 27 31 23 13
198 136 25 .intList3 35 37 - 2-
8- 7 .intList4 41 splice intList4
.intList3 splice intList4 . 45
intList3 49 intList2 intList3 .intList2
intList . .
header:Trailer
) (
)( ) ( .
.
.
. .
.
.
header
. trailer
. header trailer
. .
.
. " "A
" ."zzzzzzzz header " "A
trailer " ."zzzzzzzz 48-5 .

:48-5 header.trailer
header trailer header.trailer
49-5 header.trailer

361

:49-5 Header.Trailer
header trailer:
.1 ) (.
.2 .
.3 .
.4 .
.5 .
.6 .
.7 .
.8 .
.9 .
.10 .
header) .trailer
11 (.
:
.
50-5 52-5 .

:50-5 .

:51-5 .
first
. first
. first first->link .
52-5 .

362

:52-5 .
:
.11 ) (.
.12 .
.13 .
.14 .
.15 .
.16 .
.17 .
.18 .
.19 .
.20 .
) . 12
(.
: :

.
.
. :
.1 .
.2 .
.3 .
.4 .
.5 .
.6 .
.7 .
.8 .

363

.
.
:
:
.
.
.
. .

. 1 2 .
:1 :
: .
:
.
.
.
.
.
.
:
.1 : .
.2 .
.3 .
.4 ) (
.
.5 )( .
.
.6 -
.

364

.
.
.
:

365

366

videoType .
<< .videoType
.videoType

367

368

:

.
. .
) 53-5 .(count

:53-5 .videoList
linkedListType .
.

. .linkedListType videoListType
linkedListType .

369

: videoListType

370

;)bool videoSearch (string vTitle


//
// title .
// : true
// .false
;)bool isVideoAvailable (string vTitle
// true
// .
;)void videoCheckOut (string vTitle
// .
// : .1
;)void videoCheckIn (string vTitle
// .
// : .1
;)bool videoCheckTitle (string vTitle
// .
// : true vTitle
// .false
;)void videoUpdateInStock (string vTitle, int num
// .num
// vTitle .
// : = +
;)void videoSetCopiesInStock (string vTitle, int num
// .
// vTitle
// num .
// : =

371

;) ( void videoPrintTitle
// .
:
void searchVideoList (string vTitle, bool& found,
;)nodeType<videoType>* &current
// .vTitle
// : found true
// .false current .
videoListType linkedListType .
linkedListType videoType .
videoListType .
videoListType .
.videoType videoType
videoTitle copiesInStock .videoType
videoListType .
.
.

.
. found true
.

372

searchVideoList videoListType
. .
.54-5

:54-5 .
info videoType
:
) . .(videoType
.55-5

:55-5 .info
.
videoType / .
current . .56-5

373

:56-5 current .
:
current->info
info .
.title:
)current->info.checkTitle (title

title ) . checkTitle .
.(videoType
) copiesInStock (
.10 copiesInStock .
:
current->info.copiesInStock = 10; //illegal
. setCopiesInStock :
;)current->info.setCopiesInStock (10

374



.
:

found true current


. found false current
.NULL
videoListType:

375

376

377

:2 :
: :
.
.
.
.
.
) (
.
personType 5-1 1
.
customerType personType .
personType
.customerType
personType:
.1 .
.2 .
.3 .
.4 .
customerType:
.1 .
.2 .
.3 .
.4 .
.5 .
) . 14
(.
:
.
.
:

378

) (






.
.
.
createVideoList .
displayMenu
. main:
.1 .
.2 .
.3 ).(createVideoList
.4 ).(displayMenu
.5 while .
. 2 3 :
createVideoList.displayMenu
:createVideoList
. main

main . .
. :
. .
. .
. .
:displayMenu .
:
:1 .

379

:2 .
:3 .
:4 .
:5 .
:6 .
:9
:4

:1 . .
.
. ""
""
:2 . .
.
.
""
:3 . .
.
.
""
:4 . .
.
.
<
""
" "
""
:5
:6 .
:

380

381

382

383


.1
.
.2
.
.3 .
.4 .
.5
.
.6 )( .
.7 .

.8 ) (first ) (head
.
.9
) (head .
.10 :
.
.11 .
.12
.
.13
)
(.
.14 list .list
.15 ) (4
assign
push_front pop_front frontback remove remove_ifunique
splice sort merge.reverse
.16 header trailer .

384

.17 header trailer


. header.trailer
.18 header trailer
header.trailer
.19
.

.1 :
-

- .
- .
-
.
- )( header trailer
.
- head .
57-5
. info-link 2 .7
) . list p s A B .(nodeType

:57-5 2 .7
.2 C++:
cout<<list->info; .
cout<<A->info; .
cout<<B ->link->info; .

385

cout<<list->link->link->info .
.3
-

list->info >= 18

list->link = = A -
A->link->info = = 16 -
B->link = = NULL -
list->info = = 18 -
.4 :
-

;A = B

list->link = A->link; -
list->link->info = 45; -
*list = B; -
*A = *B; -
B = A->link->info; -
A->info = B->info; -
list = B->link->link; -
B = B->link->link->link; -
.5 C++ :
-

A .info 23

- list .info 16
- B .
- list .
- 25 .35
- info 10 .A
- info 23 .
.6 C++

386

.7 C++ .
.

.8 C++

info-

link info list) .int ptr .(nodeType

.9 C++
link info list) .int ptr .(nodeType

387

info-

.10 C++ ) linkedListType (.


.11 :
999- 75 48 19 78 36 45 32 4 30 18
C++ ) linkedListType (.

388

.12 intList :
}intList = {3, 23, 23, 43, 56, 11, 11, 23, 25
intList :
;) ( intList.unique
.13 intList1 intList2 :
}intList1 = {3, 58, 78, 85, 6, 15, 93, 98, 25
}intList2 = {5, 24, 16, 11, 60, 9
intList1 :
;)intList1.splice (intList1.begin ( ), intList2
.14

389

.15 videoType .
.16 videoListType .


) .1 ( 13 500
.
:
-

- .
.2 linkedListType :
-

) .
(.

- ) . (.
.3 linkedListType :
-

k .
.

- k
.
.4 splitMid ) (
. .34 65 89 72 13
89 72 13 .34 65 34 67 12
65 67 12.65 34
-

splitMid linkedListType :

390

// ) (
// : .
// : first last
// Sublist.first . sublist.last //
.
:

myList ) 12 89 27 65 34 ( . :
;)myList.splitMid (subList
myList myList 27 65 34
subList .12 89
- .splitMid
.5 splitAt .
oldList :
10

48 56 92 28 6 34 18

.info 6
34 18 10 48 56 92 28 6
-

:linkedListType

// info .
// : .
// : first last

391

// secondList.first secondList.last
// .
:

myList ) 12 89 27 39 18 65 34 (.
:
;)myList.splitAt (otherList, 18
myList myList 65 34
otherList .12 89 27 39 18
- .splitAt
.6 - :orderedLinkedListType

//
// list1 .list2
// : list1 list2.
// : first
list1 // list2.
: :

list1 7 6 2 list2 5 3
.8 :
)newList.mergeLists (list1, list2
8 7 6 5 3 2
newList . list1 list2.
- mergeLists .mergeLists
.7 insertNode orderedLinkedListType
.
392

insertNode .
.
.
.8 back .
.orderedLinkedListType
.9 copyList
.doublyLinkedList
.10 .doublyLinkedList
) .11 header .(trailer
header.trailer
-

header trailer
.

- ) .
header trailer (.
- .
) .12 ( .
-

- ) .
(.
- .
.13 seqSearch . :

.seqSearch
) .14 (
-

customerType
.

393

- customerListType
.
) .15 ( .
.16
.

394


6

:
************
***********
.
.

.
:
.
.
.
:

! 0 1 n (n-
!) 1 .n !) (n-1 .

(n-1) > 0

2-6 .1-6 n
! n !) (n-1 ) ! n
( !) (n-1 .n
! .3 3 = n n > 0 2-6
:
!3! = 3 2
! 2 2= n n > 0 2-6 :
!2! = 2 1
! 1 2-6 .n = 1>0:
!1! = 1 0

395

1-6 ! 0 .1 ! 0 ! 1 .1! = 1 = !2
2 1! = 2 1 = 2 .3! = 3 2! = 3 2 = 6
1-6 .
2-6 . 1-6
2-6 1-6 )
( 2-6 .
: .
:
) (.
.
.
.
.
.
.
.
.
.
.

1-6 :
;cout<<fact (4)<<end1

396

:1-6 )fact (4
cout :
24
1-6 fact
.
fact :
.

.
.
)( .
.

397

:
.
.
.
.

.
.
.
.
. .

. fact .
:
1-6
.
.
. .
.
.

.
) (
.
.
:
-

- .
.
- .
- .

398

:
1-6 5-6 C++
.
:1-6 :
.
.2-6

:2-6
2-6 .10
list

list

] [a]list [b ] list [a] list [a+1 ....] .list [b


] list [0]list [5 ] list [0] list [1] list [2] list [3 list
] [4] . list [5 ] list [1]list [5

] list [1] list [2

] list [3] list [4] . list [5 list


.
list 1 . list
.1 ] list [a]list[b list
] [a+1]list[b ] .list [a
] list [a]list [b :
) ) ]maximum ( list [a], largest (list [a + 1]list [b
.2-6
] .list [0]list [5 list:
) ) ]maximum ( list [0], largest (list [1]list [5
list ] list [0

list

] .[1]list [5 ] list [1]list [5


.1 ] list[1]list [5 :
) ) ] maximum ( list [1], largest (list [2]list [5.

399


. 1
.
.
:
: 1
.
: 1
]list [1]list [b
-

] list [a+1]list [b .max

- ] list [a:max
)(list [a] >= max
] list [a]list [b ].list [a

] list [a]list [b .max
C++ :

.3-6

:3-6

400

:
;) cout<<largest ( list, 0, 3
3 = upperindex . 4-6
).largest (list, 0, 3

:4-6 )largest (list, 0, 3


) largest (list, 0, 3 12 .list

401

C++ largest :

:
intArray76 :
:2-6 :
) (5 .

. .reversePrint
.

402

.5-6

:5-6 .
5-6 :
5 10 15 20
.
.
. )
( . .
.1
.
:

:
. .
.
) . current (.

. current
.NULL .if
if .

. ) .
(.
.

403

:
first >.nodeType<Type
.5-6
. .6-6

:6-6 ;)reversePrint (first


:printlListReverse

404

reversePrint printListReverse
.orderedLinkedListType
:

printListReverse reversePrint
. reversePrint
.printListReverse
:3-6 :fibonacci
:
... 34 21 13 8 5 3 2 1 1
) a1 (a2 n n
>= 3 :
:

.
.fibonacci

n
an .n >= 3 fibonacci .n

.:

405

rFibNum fibonacci .
rFibNum Fibonacci n n
. rFibNum Fibonacci n .
Fibonacci Fibonacci .Fibonacci
Fibonacci Fibonacci Fibonacci .
Fibonacci Fibonacci )
.(Fibonacci Fibonacci n a
Fibonacci b Fibonacci n Fibonacci :n

:
)rFibNum (2, 5, 4
2 = a 5 = b .4 = n Fibonacci
2 .5 n 2<4:
.1
) rFibNum (2, 5, 3) .rFibNum (2, 5, 2 rFibNum
) .(2, 5, 3 2 = a 5= b .3 = n n 3:
.1 .
) rFibNum (2, 5, 2) .rFibNum (2, 5, 1 rFibNum
) (2, 5, 2 2 = a 5 = b .2 = n 3-6 :
.1rFibNum (2, 5, 2) = 5 :1.
) rFibNum (2, 5, 1 2 = a 5 = b .1 = n
3-6
.1rFibNum (2, 5, 1) = 2 :2.
) rFibNum (2, 5, 2) rFibNum (2, 5, 1 ).1( :
rFibNum (2, 5, 3) = 5 + 2 = 7
) .rFibNum (2, 5, 2 ).1 (1. ).5 = rFibNun (2, 5, 2
) rFibNum (2, 5, 3) rFibNum (2, 5, 2 ) (1 :
rFibNum (2, 5, 4) = 7 + 5 = 12
:

406

cout<<rFibNum (2, 3, 5)<<end1;:


2 3 .
7-6 ) rFibNum (2, 3, 5 13 Fibonacci
2 .3

:7-6 )rFibNum (2, 3, 5

407

C++ :rFibNum

: .
:1
Fibonacci2 :
Fibonacci5 :
Fibonacci 631 :
:2

408

Fibonacci3 :
Fibonacci4 :
Fibonacci6 :
Fibonacci 629 :
:3
Fibonacci12 :
Fibonacci18 :
Fibonacci15 :
Fibonacci 159582 :
:4-6 :
.
.
64 . .
64 .
:
.
.
.

.

. 8-6 .

409

:8-6
.
. 1 .3
.
1 2 1 .3
2 3
64 ) arbitrary (.
1 . 3 3
.2 3 1 .3
2 3 .
1 . 9-6 .

410

:9-6 .

411

64 . 64.
64 1 3 63
. 63 1 2 64
1 .3 63 .2 63
2 3 26 2 1
63 2 .3 62 .
. 1
n .1 n
.1 n-1 1 2 3 .
.2 n 1 .3
.3 n-1 2 3 1 .
C++:

1 .3
1
1 3

1 64

1 3

:
:

.
.:

412

1 3
. 15

.:

33 .
1 )= (109 .
:
264 :
500 264 1 .
:5-6 :

-10 .2 .
x . x 2
33 10 2 % 33 1 28 28
2 % .
10
.
.35 35 .2 17
- .1 17 2 8
- .1 8 2 4 -
. .
35 17 17
8 . 35 17
) 35 (2 .35
num 10
num/2 num
.num/2

413

) binary (num
:num
= binary (num) .1 = .
= binary (num) .2 ) (num/2 num/2 < num.
:

10-6 :
;)decToBin (13, 2
num 13 .2

:10-6 ;)decToBin (13, 2

414

if 5 .
4 3 1
2 1 .1
:
1101
C++ :decToBin

: .
57 :
= 57 111001

415



.
while for dowhile
. .
.
.
.Fibonacci

.
.
.

.

.
) (
)( . )(
.
)( .
.
)( .
.
.
.
.

.
) .
( .
.

416

: n :
.
: ) 8 8 (
.
11-6 .

:11-6 .
1850
. .1950
1960
.
:

.
.

.
:
n

x1

. tuple xi
i .i tuple
) (x1-x2-x3-x4-x5-x6-x7-x8 xi i .i
417


. xi .8 xi 1
(x1-x2-x3-x4-x5-x6-x7-x8) tuple xi 1
.8 xi xi

tuple

tuple
) (x1-x2-x3-x4-x5-x6-x7-x8 . tuple .!8
.
) 4 4 (12-6
.

:12-6 .
) 13-6(.
) (.

:13-6 .
.
.
) 13-6(.
418


.
. ) 13-6( . .
. ) 13-6( .

.
.
2
. .
.
.14-6

:14-6 .
:
3
) .3 C++ (.

.(0) tuple
.(2 0) tuple
. ) (2 0 2 tuple
(3 0) tuple .
) (3 0 tuple

) .(1 3 0

) (1 3 0
) (1 3 0 .
) (1 3 0
.tuple
) .(1 ) (1 ) (3 1) (0 3 1)1

419

(2 0 3 .
.15-6

:15-6 .
:
.
.
.
.
8 8 .16-6 7
) .7 C++ (.

:16-6 8 8

420

) (4 0) (5 1) (6 2) .(7 3
= 6-2 = 5-1 = 4-0

.4-

.4- = 7-3
.
.
) (6 0) (5 1) (4 2) (3 3) (2 4) (1 5) .(0 6
+ = .6 +
.
.
) ( ) ( ) (
) ( . + =
+ = . =
= .
-| = | | | -|

tuple queensInRow
8 ] queensInRow [k k
.k queensInRow[0] = 3
) 3 ( ) (.
k-1 k-1 . k
.k ) canPlaceQueen (k, i
k i k .
k-1 k-1 k
k k

.k

k i
) .(k, i
:

421

)canPlaceQueen (k, i

for I
) .(k, i for false
.true
:

// 8.

// : true k i
.false
//

422

;)void queensConfiguration (int, k


// .
// .
// : n-tuples .
;) ( void printConfiguration
// n-tuple .
;) ( int solutionCount
// .
// : .
nQueensPuzzle :

queensConfiguration
. k k :

423


.1 .
.2 .
.3 .
.4 .
.5 .
.6 .
.7 .
.8 .
.9 .
.10 .
.11
.12 .
.13 :
424

.

.

. )(
.
.
.14 .
.15
.
.16
.
.17 :
-

- .
.
- .
- .
.18
.
.

.

.1 :
-

- .
- .
- .
- .

425

.2
.3
.4
.5
.6
.7 :

- .
- mystery
- ) mystery (0 .
- ) mystery (5 .
- ) mystery (-3 .
.8 :

:
-

- .
-
;)'funcRec (5, 'A
.9 :

426

;)exercise (0

exercise (5); -
exercise (10); -
exercise (-5); -
.10 :


cout<<test (5, 10) <<end1; .
cout<<test (3,19) <<end1; .
.11 :


cout<<func (0) <<end1; .
cout<<func (1) <<end1; .
cout<<func (2) <<end1 .
cout<<func (5) <<end1 .
.12 intArray ) length (

.intArray low high

=< 0

low < length 0 <= high < length .low < length lowhigh

427

.intArray intArray low


.high
.13 .
.
.14 :
10
.
: r
n r n


. r n

) C(n, r r
.n ) C(n, r :

. .C(n, 0) = C(n, n) = 1
).C(n, r) = C(n 1, r 1) + C(n 1, r
-

) C(n, r .

- ) C(5, 3 ).C(9, 4


.1 .
4 :
****
***
**
*
*
**
***
****

. 4 .

428

.2 :
*
**
***
****
****
***
**
*

. 4 .
.3 :
*
* *
* * *
* * * *
* * *
* *
*

. 4 .
.4 vowels
.
.5 int .
.6 .
" "madam .
.
true false .
.
.7
.
.

429

.8 reverseDigits
.
.9 power x y x
.xy .xy

0 y

0 y:

.
) .10 ( x y
x y )gcd (x,y

% .mod operator
gcd
.
.11 ) 12
( .
.12 ) 13
( .
.13 ) 14
( .
.14 " 5-6 "
. ) (8 )
(16 . C++
. 4 3 2 1 0

430

6 5 .7 7 6 5 4 3 2 1 0
.F E D C B A 9 8 A 10 11 B
. )
( .
) 8 ( ) 16 ( . ab
a .b 7510 75 ) 10 ( 8316
83 ) 16 ( .:

2 8 16 .
b b 2.36
n b
.
20 F E D C B A 9 8 7 6 5 4 3 2 1 0
I H G.J
b b 2.36
.
:
9098 20
692 2
753 16
) .15 (
. A
01000001 . A ASCII
.65 A 01000001 A
.65
10
.2 5-6

431

.
2 .10
2 10 .
. rightmost .
rightmost bit 1
2 . .1001101 :

0 1 2 3 4 5 6
1 0 1 1 0 0 1

.
2 . 1001101
:
(1) :
) (2 .

. 1 .
2 .
.mod

11000101 : 10101010 1111111110000000
.1111100000
.16 sqrt cmath
.
tolerances :
x a x
.tolerance :x = a
. a * a - x a x
tolerance :
. a) (a * a + x) / (2 * a .a
a * a - x .a * a x

432


.
.17 .n
4 = n.8 = n
) .18 ( .

.
. 5 5
6 6 17-6 .

:17-6 .
.

.

433

:
.
.
.
.
.
.
.stack
.
.
:

.
.
.

6 .

.

.
.
. .

.
.

434

.
. 1-7 .

: 1-7 .

.
) ( .
.
:
.
.
push
. /
top pop
. 2-7 3-7 push top.pop
push top pop :
. .

:2-7
435

:3-7 .
B
)3-7( C
)3-7( .
)3-7( . D
)3-7 ( .
) 3-7(.
/
. pushtop
pop ) isFullStack ( ) isEmptyStack
( .
.
initializeStack .
destroyStack
.
.
.
:
:
:initializeStack .
:destroyStack .

436

:isEmptyStack .
true .false
:IsFullStack .
true .false
:push
.
.
:top
.
:pop
.
.
.
.
:
.

.
.

.
) (
.
.
.
.stackTop
stackType .
) (.
.100 stackType
) (
. .

437

// .
// .
// : = 0

438

;) ( bool isEmptyStack
// .
// : true .false
;) ( bool isFullStack
// .
// : true .false
;) ( void destroyStack
// .
// : = 0
;)void push (const Type& newItem
// .
// : .
// :
// .
;) ( Type top
// .
// : .
// :
.
//
;) ( void pop
// .
// : .
// : .
;)stackType (int stackSize = 100
//
// .
// .100
// :
// = 0 = .
;)stackType (const stackType<Type>& otherStack
// .
;) ( -stackType
//
// .
// : .
:
; // int maxStackSize .
// .
;int stackType
// .
;Type *list

439

;)void copyStack (const stackType<Type>& otherStack


// .
// :
//

C++ stackTop
.stackTop stackTop

.1 stackTop
copyStack .
.
.
4-7 stack .stackType
stackType . stackTop
1 stackType stackTop .
= .100

:4-7 .

440

list ) (
.
stackType .
:
.initializeStack stackTop
stackop ) . .(5-7

:5-7 .
initializeStack:

:
.
stackTop .
) ( stackTop
. destroyStack:
441

:
stackTop . stackTop
. isEmptyStack:

:
.isFullStack stackTop
. isFullStack:

:
. stackTop
stackTop 1 stackTop
. :

. .stackTop
. .stackTop
6-7 7-7 .
.6-7

442

:6-7 .y
y .7-7

:7-7 .y
.
push . push:
443

.
.
push )
stack .(stackType

:
top .

:
stackTop .1
8-7 9-7 .
.8 -7

444

:8 -7 .d
.9-7

:9-7 .d
.
pop .
pop:

445

.
.
pop ) stack .(stackType

:
copyStack .
.copyStack
. :

:
.
stackTop .

100 .100
) ( stackTop .
:

446

:

)( .
:

)=(:

. stackType:

447

) arrayListType .(3
.1-7
1-7 .stackType

:1-7 stackType

isEmptyStack

)O(1
)O(1

initializeStack

)O(1

destroyStack

)O(1

)( constructor

)O(1

top

)O(1

Push

)O(1

pop

)O(1

copyStack

)O(n

isFullStack

)O(1
)( Destructor
)Copy constructor ( )O(n
)O(n

:

.
.
stackType .myStack.h
.
448

:1-7
stackType
. .
) . stackType
.myStack.h

:
23 45 38 :tempStack
449

38 :intStack
.
: :GPA
C++

. .
:
:
3.8
3.6
3.9
3.7
3.4
3.9
3.4
:
. 3.9
.
:
.
. .
)( . :
.1 .
-

- .
- .
.2 .
.
.3 .
.
1 3
.
:

450

;double GPA

// .

;double highestGPA

//

;newString name

//

;stackType<newString> stack

//

newString 3
.newString
:
.1 .
.2 .
.3 .
.4
. .
.5 .
.6 =
.7 .
.8

.9 .
.10 .
:
// :

451

452

:
(Ch7_HighestGPAData.txt) :
3.4
3.2
2.5
3.4
3.8
3.8
3.6
3.5
3.8
3.7
3.9
3.8
3.9
2.7
3.9
3.4
:
= 3.90
:

:
) (
.
. .

) ( .
.

453

stackTop
stackTop 1 . stackTop
: .
stackTop
. stackTop
) (
.
:

// .
;) ( void initializeStack
// .

454

// : .NULL = stackTop
;) ( bool isEmptyStack
// .
// : true .false
;) ( bool isFullStack
// .
// : .false
;) ( void destroyStack
// .
// : = 0
;)void push (const Type& newItem
// .
// : .
// :
// .

;) ( Type top
// .
// : .
455

// :
.
//
;) ( void pop
// .
// : .
// : .
;) ( linkedStackType
//
// NULL = stackTop :
;)linkedStackType (const linkedStackType<Type>& otherStack
// .
;) ( -linkedStackType
//
// : .
:
// .
;nodeType<Type> *stackTop
;)void copyStack (const linkedStackType<Type>& otherStack
// .otherStack
// : otherStack
.
//

. .
isFullStack .
isFullStack .

.
.

456

:2-7
: .linkedStackType
) .(10-7

:10-7
: 11-7 .

:11-7
11-7 C
.C
.
:
.
. stackTop .NULL
:

457

:
destroyStack .
stackTop .
. stackTop NULL
:

:
.

.
.destroyStack destroyList stackTop .NULL
initializeStack:

isEmptyStack .isFullStack
stackTop .NULL
) .

458

( isFullStack .false
:

push top .pop 11-7


) (push .stackTop pop
stackTop
.stackTop
:Push
.12-7

:12-7 .
.D
D .
.stackTop:

459

newNode info
. .13-7

:13-7
newNode -> link = stackTop; :
.14-7

:14-7 ;newNode -> link = stackTop

460

:
;stackTop = newNode
stackTop .15-7

:15-7 ;stackTop = newNode


push:


.
:
:

461

:pop
pop .
.16-7

:16-7 .
:
;temp = stackType
temp :
;stackTop = stackTop-> link
\
.17-7

462

:17-7 :
; temp = stackType ;stackTop = stackTop-> link
:
;delete temp
.temp 18-7 .

:18-7 ;delete temp


pop:

.
copyStack .
5
.

.
) ( .
.include

63

.linkedStackType
:
;linkedStackType<int> stack
stack linkedStackType .int
:
;linkedStackType<newString> stringStack
stringStack linkedStackType
.newString
:linkedListType
push insertFirst
5 .
initializeList initializeStack isEmptyStack isEmptyList
linkedStackType .linkedListType
pop isFullStack .
linkedStackType .linkedListType
.

464

465

: :postfix
) (
. a + b +
a .b .
.
. a + b * c *
a b + a .b * c

) postfix (+ a b ) postfix
(a b + . :
a+b*c
postfix:
abc*+
postfix .
:3-7
2-7 postfix .

:2-7 infix postfix

466

postfix


a+b

ab+

a+b*c

abc*+

a*b+c

ab*c+

(a + b) * c

*ab+c

)(a b) * (c + d

*abcd+

(a + b) * ( c d / e) + f

ab+cde/-*f+

postfix
.
postfix postfix . postfix
:
.
.
:
=*63+2
) .
postfix . (.
=*63+2
.1 6 . )

:19-7 6
=*63+2
.2 3 . ) .(20-7

467

.(19-7

:20-7 3
=*63+2
.3 + .
.
) 21-7.(22-7

:21-7
: + 1 .9 = 3 + 6 = 2
) .(22-7

:22-7 + 1 2 9
=*63+2
.4 2 ) .(23-7

:23-7 2.
=*63+2
.5 * .
.
) 24-7.(25-7

468

:24-7
: * 1 .18 = 2 * 9 = 2
) .(25-7

:25-7 * 1 2 18
=*63+2
.6 = . .
.
.26-7

:26-7

.6 3 + 2 * = 18
:
.1 + : - * / =.
. + * / .

.
. = .
.
.2 + * . /
.
)(
.
469

:
= (i)7 6 + 3 ; 6 -
= * ( ii) 14 + 2 3
= ( iii) 14 2 3 +
) ( i ) ( ii + ) (iii
. ) (iii )=(
.
postfix :
= * #6 #3 + #2
# #
) ( . # ) (
) ( .
+ * ./
postfix .
.
.
.
:
:

470

Evaluate:
) (
. .
.
.
:

471

:Discard .
= . :

472

473

474

475

:
:
= * #35 #27 + #3
#26 #28 + #32 #2 ; - #5 /
= #23 #30 #15 * /
= #2 #3 #4 +
= ; * #20 #29 #9
= #25 #23 - +
= #34 #24 #12 #7 / * + #23 -
:

: :

.
.27-7

:27-7

.
476



.
.
.
info .
20 .15
.
27-7 .info 5, 10, 15 20
info 15 15 info 10 .
.
.
stack linkedStackType current
.first :

1 current ) .(28-7

:28-7 ;current = first


current NULL 3) 4 .(29-7

477

:29-7 ;) stack.push(current

= curresnt

;current -> link


4 .2 current
NULL true 3) 4 .(30-7

:30-7 ;) stack.push(current

= curresnt

;current -> link


4 2 . current
NULL true 3) 4

478

.(31-7

:31-7 ;) stack.push(current

= curresnt

;current -> link


4 2 . current
NULL true 3) 4

479

.(32-7

:32-7 ;) stack.push(current

= curresnt

;current -> link


4 2 . current
NULL false while .2 32-7

. :

5 true .
6 7 .8 6 current
7 ) .(33-7

:33-7 ;) ( current = stack.top ( stack.pop


;)

480

8 current -> info 20 .5


true 6 7 .8
6 7 .34-7
:

:34-7 ;) ( current = stack.top ( stack.pop


;)
8 current -> info 15 .5
true 6 7 .8
6 7 .35-7

:35-7 ;) ( current = stack.top ( stack.pop


;)

481

8 current -> info 10 .5


true 6 7 .8
6 7 .36-7

:36-7 ;) ( current = stack.top ( stack.pop


;)
8 current -> info 5 .5
false while while
:
5 10 15 20
) stack (:
stack .
. stack
stack .stack stack
. 3-7
.
:3-7 stack

size

empty

true false

)push (item

top

pop


482

size empty push top pop


.

= =

.
4-7 .
:4-7

:
:6 3 :intStack
:8 20 :intStack
:9 16 8 20 :intStack
.

:
.1 .

483

.2 .
.3 :

.
.4 .
.5 .
.6 .
.7 postfix .
.8 postfix .
.9 postfix :
-

-
.
.10 stack .

:
.1 :

484

.2 :

:
999- 5 10 23 34 45 14
.

.3 :postfix
6 4 + 3 * 16 4 / - = .
12 25 5 1 / / * 8 7 + - = .
70 14 4 5 15 3 / * - - / 6 + = .
3 5 6 * + 13 - 18 2 / + = .
.4 ) postfix
postfix 10 (.
(A + B) * (C + D) E .
A (B + C) * D + E / F .
{(A + B) / (C D) + E} * F G .
A + B * (C + D) E / F * G + H .
485

.5 postfix.
a b * c + .
a b + c d - * .
a b - c d * .
.6

.7

486

.8 printListReverse
. linkedListType
5.
.9 second
. .
.10 clear ) stack
( .

:
.1 copyStack
linkedStackType .

487

.2
. = = stackType true
.false
template = = . .
.3 2 ) .linkedStackType
copyStack .1
(.
.4 . :stackType
:

:
stack1 stack2 . stack1
stack2 . stack2
.stack1
. template .reverseStack
.reverseStack
.5 4 4 linkedStackType .
)) copyStack
.1
(.
.6
. } {25 + (3 6) * 8
.
.7
.

488

.8 15 6
.
.
.9 4-6 6
.
.
).10 (postfix postfix
. postfix :
-

- .postfix
- .
-
. .
- :
-1

.postfix
-2 .
-
.postfix
) ( + : -* ./
.
postfix :
:getInfix .
:showInfix .
:showPostfix .postfix
:
:convertToPostfix postfix postfix
.postfixString
:precedence .
true .false

489

.
:
A + B C; .1
(A + B) * C; .2
(A + B) / (C D); .3
A + ((B + C) * (E - F) G) / (H I); .4
A + B * (C + D) E / F * G + H; .5
:
A + B C; :
A B + C :postfix
.11 : postfix
stack .postfix
.12 10 stack
.postfix

490

:
.
.
.
.
.queue
.
: .
.
.

.
.
.
.
.
.
. .
:

.

.
.

491


.
.
:
.
:

addQueue .deleteQueue
addQueue
deleteQueue ) isEmptyQueue : (
) isFullQueue (.
initializeQueue
destroyQueue .
front back
. :
:initializeQueue .
:destroyQueue .
:isEmptyQueue .
true .false
:IsFullQueue . true
.false
:front . .
:back .
:addQueue rear
.
:deleteQueue
.
.
.
queueFront.queueRear
:

492


.
maxQueueSize .

queueFront queueRear .
queueFront
queueRear .
queueRear
.queueRear queueFront
. queueRear addQueue queueFront
.deleteQueue

. .100
. queueFront queueRear
. :
;) 'addQueue ( 'A
.1-8

:1-8 addQueue
:addQueue
;) 'addQueue ( 'B
;) 'addQueue ( 'C
.2-8

493

:2-8 addQueue
:deleteQueue
;) ( deleteQueue
.3-8

:3-8 deleteQueue
A ) (addQueue
D ) (deleteQueue .
:
AAADADADADADADADA
queueRear
.
) .(4-8

:4-8 AAADADADADADADADA
) queueRear
( .queueFront
queueFront
.
.

494


) .(5-8

:5-8

.
.6-8

:6-8 9899
:
;) 'addQueue ( 'Z
.7-8

495

:7-8 addQueue
queueRear
:

queueRear < maxQueue 1 queueRear + 1 <= maxQueue 1


.(queueRear + 1) % maxQueue = queueRear + 1 == queueRear
) maxQueue 1 queueRear ( queueRear +
1 == maxQueue .(queueRear + 1) % maxQueue == 0
queueRear .
queueFront .
.
.
:1
.8-8

:8-8
:
;) ( deleteQueue
.9-8

496

:9-8 deleteQueue
:2 .10-8

:10-8 99.
:
;) 'addQueue ( 'z
.11-8

:11-8 addQueue
9-8 11-8 queueFront.queueRear
9-8
11-8 . :
.
. .count
queueFront queueRear count .
count .
initializeQueue destroyQueue count .
.
queueFront
)( . queueRear
497

== queueFront

.queueRear ) queueFront
( .
.queueFront
queueFront 100
99 ) .(12-8

:12-8
. count
.
) .(13-8
.
.100

;&>const queueType<Type>& operator = (const queueType<Type


498

// .
;) ( bool isEmptyQueue
// .
// : true .false
;) ( bool isFullQueue
// .
// : true false
;) ( void iniitializeQueue
// .
// = count : = queueFront
queueRear = maxQueueSize 1

499

;) ( void destroyQueue
// .
// = count : = queueFront
queueRear = maxQueueSize 1
;) ( Type front
// .
// : .
// :
.
//
;) ( Type back
// .
// : .
// :
.
//
;)void addQueue (const Type& queueElement
// .
// : .
// : .
;) ( void deleteQueue
// .
// : .
// : .

500

:13-8 .queueType
.
:
initializeQueue
. queueFront
queueRear maxQueueSize -1 count ) . .(14-8

:14-8
initializeQueue:

:
count = =0 count
.= = maxQueueSize isEmptyQueue isFullQueue:

:
501

destroyQueue .

queueFront queueRear .count
destroyQueue .initializeQueue

:front

queueFront .

:back

queueRear .

:
.addQueue queueRear
queueRear
.queueRear
count 1 :addQueue

502

:
deleteQueue queueFront
deleteQueue:

:
.
maxQueueSize .
100
.100 queueFront queueRear .
:

503



.
:

) .
(.
:

.
queueFront .queueRear

. .
queueRear
queueFront .

504

queueFront queueRear .
.

= const linkedqueueType<Type>& operator


;)&>(const linkedqueueType<Type
// .
;) ( bool isEmptyQueue
// .
// : true .false

505

;) ( bool isFullQueue
// .
// : true false
;) ( void destroyQueue
// .
// NULL = queueRear NULL = queueFront :

;) ( void iniitializeQueue
// .
506

// NULL = queueRear NULL = queueFront :


;) ( Type front
// .
// : .
// :
.
//
;) ( Type back
// .
// : .
// :
.
//
;)void addQueue (const Type& queueElement
// .
// : .
// : .
;) ( void deleteQueue
// .
// : .
// : .
linkedQueueType .
.
queueFront .NULL
isFullQueue
) .false (.
destroyQueue .

.
isEmptyQueue isFullQueue destroyQueue
:

507

initializeQueue .
. initializeQueue
. .
.
.destroyQueue

addQueue front back:deleteQueue


addQueue .
.queueRear

508

front
.queueFront front
.
back
.queueRear back
. deleteQueue
.queueFront
:

509

.initializeQueue

. .destroyQueue
.
.
:linkedListType

) .(5 addQueue inserFirst

initializeQueue initilaizeList

isEmptyQueue

isEmprtList destroyQueue destroyList.


deleteQueue isFullQueue .
queueFront first queueRear .last

510

linkedListType

.(5
linkedQueueType linkedListTYpe
.

511

1-8 .
.linkedListType

:1-8

512

: .

999-
999- 82 11 21 91 28 56 64 76 23
999- 82 11 21 91 28 56 64 76 23 :
) queue (
.
.
queue queue .queue
513

queue .
1-8 .
:1-8 :

size
empty true false
) push (item
front
.
back
.
pop

size empty push front back pop

.
.
2-8 .
:2-8

514

==

:
:6 26 :intQueue
:7 33 :intQueue
:9 18 :intQueue
:10 33 50 18 :intQueue
.
:
.
.


. .
.
.
.

.

515

.
.
.

.
) . 10
( .
.
:priority_queue
> priority_queue<elemType
.elemType
.queue .
> .
>
.
> .
. .13
::
.

.
.
) . ( .

.
.
.
. .
.

516

.

.
.
.
.
.
.
. .
C++ .

.
) ( .
.
.


. .

.
.
.
.
.

.
:


.

517

.
.
.

.
.
.
.

.

.
. 1
5 4 .
.

. .
.1
. 100
1 100 .
.

. .

.

. ) ( .
.
5 .

518

. .
5 .
.
.

: .
:
.

. .customerType
customerType customerNumber :arrivalTime
waitingTime transactionTime .int
customerType :

.
customerType ) (15-8

519

//
//
// .
// : = customerN
= arrvTime
= wTime
= tTime
void setCustomerInfo (int customerN, int arrvTime,
; )int wTime, int tTime
// .
// : = customerN
520

= arrvTime
= wTime
= tTime
;int getWaitingTime ( ) const
// .
// : .
;)void setWaitingTime (int time
// .
// : = time
;) ( void incrementWaitingTime
// .
// waitingTime++ :
;) ( int getArrivalTime
// .
// : .
;) ( int getTransactionTime
// .
// : .
;int getCustomerNumber ( ) const
// .
// : .

521

:15-8 customerType
.customerType
setCustomerInfo customerNumberarrivalTime
waitingTime transactionTime :

.setCustomerInfo
customerNumber arrivalTime waitingTime .transactionTime
setCustomerInfo .

getWaitingTime .
waitingTime getWaitingTime .
getWaitingTime:

incrementWaitingTime :

setWaitingTime getArrivalTimegetTransactionTime

getCustomerNumber .

522

:
.
status .

. : string
Int .customerType
:
)
( ) (

.
serverType ) :(16-8

523

524

:16-8 serverType
serverType :

525

getRemainingTransactionTime :
getCurrentCustomerNumber setCurrentCustomer
getCurrentCustomerWaitingTime getCurrentCustomerArrivalTime
.getCurrentCustomerTransaction Time

:
. .
:
.
.
.
.

.
.

526

:

""

" " .
serverListType ) :(17-8

;)serverListType (int num = 1


//
// : = num
527

// .
// num .
;) ( -serverListType
//
// : .
;) ( int getFreaaServerID
// .
// :
// .1-
;) ( int detNumberOfBusyServers
// .
// :
void setServerBusy (int serverID, customerType cCustomer,
;)int tTime
// "".
// : cCustomer
// serverID
// ""
// .tTime
; )void setServerBusy (int serverID, customerType cCustomer
// "".
// : cCustomer
// serverID
// ""
// .
;) ( void updateServers
// .
// :
// .
// ""
//
// .

528

; )void updateServers (ofstream& outFile


// .
// :
// .
// ""
//
// .

:17-8 serverListType
.serverListType :

529

getFreeServerID
1- . :

getNumberOfBusyServers
:

setServerBusy " " .


"" .
tTime .cCustomer
.
:

530

.updateServers
.
.1 " "

.
updateServer .
. :

531

:

.
.1 queueType

. waitingCustomerQueueType
queueType .
waitingCustomerQueueType:

532

waitingCustomerQueueType queueType
. waitingCustomerQueueType
linkedQueueType . .
. :

updateWaitingQueue .
waitingCustomerQueueType .queueType
queueType updateWaitingQueue .
front .deletQueue
.addQueue
addQueue . front
deleteQueue addQueue
. front deleteQueue
addQueue
isEmptyQueue isFullQueue .

533

.
.
. .
.
.
.
1- .
1-
. 1-
.
.
. :updateWaitingQueue

:
:
.
.
.
.
.

534

.
. setSimulationParameters .
:


.
. .
) serverID ( :
.1 .
;) ( customer = customerQueue. Front
;) ( customerQueue. deleteQueue
.2
.
) ( totalWait = totalWait + customer. getWaitingTime
.3 .
;)serverList. setServerBusy (serverID, customer, transTime

.
y :

535

y .
4 . 4
.
.0.25 = 4/1
.
.

.
.

.
4 .0.25 = .
<

rNum .0 rNum 1

> rNum

.
runSimulation .
93 96 .100 5 5
.
97 93 .
97 93 .
93 97 5
.
96 100 .
.
:
.1


waitingCustomerQueue .
.2 :

536

.
-
- 1 .
-
.
{
.3

.
runSimulation main main
runSimualtion) . 6 (.
.
5 4 .
0 1 .
:
:1
1 4
2 8
1 : 1 9
3 9
4 12
1 : 2 14
1 : 3 19
5 21
1 : 5 29
6 37
7 38
8 41
1 : 6 42

537

9 43
10 44
1 : 7 47
11 49
12 51
1 : 8 52
13 52
14 53
15 54
1 : 9 57
16 59
1 : 10 62
17 66
1 : 11 67
18 71
1 : 12 72
1 : 13 77
19 78
1 : 14 82
1 : 15 87
20 90
1 : 16 92
21 92
1 : 17 97
100
1 :
5 :
4 :
269 :
17 :
1 :

538

3 :
!12.8 :
************** ***************
:2
1 4
2 8
1 : 1 9
3 9
4 12
1 : 2 13
1 : 3 14
1 : 4 18
5 21
1 : 5 26
6 37
7 38
8 41
1 : 6 42
1 : 7 43
9 43
10 44
1 : 8 47
2 : 9 48
11 49
12 51
1 : 10 52
13 52
14 53
2 : 11 54
15 54

539

1 : 12 57
2 : 13 59
16 59
1 : 14 62
2 : 15 64
17 66
1 : 16 67
2 : 17 71
18 71
1 : 18 76
19 78
1 : 19 83
20 90
21 92
1 : 20 95
2 : 21 97
100
2 :
5 :
4 :
20 :
21 :
0 :
0 :
0.95 :
************** ***************
) :3
(.
1 4

540

2 8
1 : 1 9
3 9
4 12
1 : 2 14
1 : 3 19
5 21
1 : 4 24
1 : 5 29
6 37
7 38
8 41
1 : 6 42
9 43
10 44
...
100
1 :
5 :
4 :
8008 :
197 :
1 :
15 :
37.60 :
************** ***************
) :4
(.
1 4
2 8

541

1 : 1 9
3 9
4 12
2 : 2 13
1 : 3 14
3 : 4 17
5 21
1 : 5 26
6 37
7 38
8 41
1 : 6 42
2 : 7 43
9 43
10 44
3 : 8 46
...
100
3 :
5 :
4 :
13 :
212 :
1 :
0 :
0.06 :
************** ***************

542


.1
.
.2 .
.3

.
.4 .
.5 .
.6 front
back .
.7 .

.1 queueType 100
queueFront 50 queueRear 99
-

queueFront queueRear

- queueFront queueRear
.2 queueType 100
queueFront 99 queueRear 25
- queueFront queueRear
- queueFront queueRear
.3 queueType 100
queueFront 225 queueRear 75
- queueFront queueRear
- queueFront queueRear
.4 queueType 100
queueFront 99 queueRear 25
- queueFront queueRear
- queueFront queueRear

543

.5
. .100 queueFront
50
.6
. .100 queueFront
74 queueRear .99
- queueFront queueRear
- queueFront queueRear

.7 :
.

.8 :

:
999- 30 13 11 7 32 19 35 64 22 14 28 15
.

544

545

.9 ) C++
.(queue

.10

.11 moveNthFront n
. n . .

}queue = {5, 11, 34, 67, 43, 55
.3 = n
moveNthFront:

546

}queue = {34, 5, 11, 67, 43, 55


.12 reverseStack
. reverseStack
.
.13 reverseQueue
. reverseQueue
.
.14 queueCount ) queueType (
. .


.1 queueType
.
.2 linkedqueueType
.
.3
.
count .
. .
.4
. .
.5 count
. count .
8 . linkedQueueType
. linkedQueueType
count . addQueue
deleteQueue . queueCount
.
.6 .

setWaitingTimegetArrivalTime

getTransactionTime getCustomerNumber customerType


" :".

547

. getRemainingTransactionTimesetCurrentCustomer
getCurrentCustomerArrivalTime

getCurrentCustomerNumber

getCurrentCustomerWaitingTime getCurrentCustomerTransactionTime
serverType " :".
. runSimulation "
: " . .
.
.7 queue
.

548


9

:
.
.
.
.

3
. 5
. .
:
.
) (
.
.
.
.
:
3 5 .
.
.
.

.
. .
.

549


.

.
.
) ( .
3 arrayListType .
:

550

551

:
) (
3 .5
.
.

) (
) .(3

552

) ( . .1-
.

) (for
. .
) 1 (.
:
.

. for .

.
. .

.
.
.

.
L n
L .

553


n . .
.
. L
.
n .
L
.
.
:
.1 .
.2 .
.3 .

.
k k k .

. n .
:

:

1.000.000 500.000 .
.
:

554

.
.
.

.
arrayListType
.
:
orderedArrayType
:

5 :

:

. .
. .
" " .
.
.

555

12 .1-9

:1-9 12
75 .
) .(2-9

:2-9 ]list [0] list [11


75 ]) list [5 .(39

75

] list [5 list [5] < 75 ] list [6]list [11


.3-9

:3-9 ]list [6] list [11


] list [6]list [11 = 6

.
first last 2 .
:

= first ) C++
( = last .1
C++ .
.1-

556

.
.
) (while
.
) . 2 (.
.
:1-9
.4-9

:4-9
12 .12 1-9 first last middle
.
.
.89

557

:1-9 first last middle 89

1
2
3

first
0
6
9

last
11
11
11

] List [mid
mid
2
39
2
66
1
89

5
8
10

10 .5
.34 1-9 2-9
first last middle .
.
:2-9 first last middle 34

1
2
3
4

first
0
0
3
4

last
11
4
4
4

] List [mid
mid
2
39
2
19
2
25
1
34

5
2
3
4

4 .7
22 .3-9
:3-9 first last middle 22

1
2
3
4

first
0
0
3
3

5
2
3
4

] List [mid
mid
last
2
39
5
2
19
2
2
25
3
) (first-> last

.6
:
L 1000 x
.L L .x
L .5-9

558

:5-9 L
loop x ] L[0]L[999 1000
. while x ]) .L[499 .(6-9

:6-9
.L[499] x ] x < L[499 while x
] L[0]L[498 while x ] .L[500]L[999
] .x < L[499 while x ] L[0]L[489
499 .7-9

:7-9 .
while x ] .L[249 .L [249] x
] .x > L[249 while x ] L[250]L[498
249 .8-9

:8-9 .
while . 1000
= 1024

while 11 x

559

) .L " "( . while


x L 22
x .L 500
x .L
L
while

.1000000 = 1048576 1000000

21 .L
while ) (
L 42 .
500.000 .L
:
L n L
.

n
.
:
n


.
:
.
. 5 .
.


.
.
) insertAt (arrayListType ) .
560

1- .

(. :
) .
(.


insertAt .
insertOrd :

561

. 6 .
insertOrd
orderedArrayListType :

4-9 .
:4-9 .n

***

***


***
***

:

. .

. :


.
: L .n > 1 L . ) SRH(n

.

x n

:
.

562

.
:
: .

. n

n . :

.

.

. .1

. .
.
.
x h
X ) h(X h .x h )h(X
. .m < )0 h(X
.m X
]) HT[h(x .
.
:


.
.
.
.

563

.
.
HT b ] .HT[0], HT[1], , HT[b 1
r . br = m m .HT
1 = r .
h X t t

)h(X

. X1 X2 X2 X1
. X .h(X) = t t . X1

X2 .X2 X1 ) h(X2) = h(X1


. 1 = r 1 .
:
.
.
.
Htsize .
1
.
: :

.
: h
.

.
: X
. .
) ( : X

X
) (C++:

564

. C++
:

:

.
. .
: ) ( )
( .

. .
: :
)h(X
X .X
.
.
:
X .
) h(X . h(X) = t

)0 h(X

.HTSize 1 ] HT[t .
] HT[t . t
.

.

565

.mod t
.(t + 2) % HTSize, , (t + j) % HTSize

t, (t+1) % HTSize,

:
(h (X) + j) % HTSize
j .j
:

.

.
20 .9-9

:9-9 20
.
) .(20/1
.10-9

566

:10-9 20
. 9
6 7 8 .9
9 .20/4 14
.20/5
.11-9

:11-9 20
14 20/9
15 16 17 .20/1
. .
.
c .1
:
(h(X) + I * c) % HTSize
2= c) 2k = h(X ) h(X
. 2= c) 1 + 2k = h(X ) h(X

. c .HTSize
:
. I
:
ri i 1 .1 HTSize
.
2-9 .
:2-9

567

101 X1 X2 )26 = h(X1


) .35 = h(X2

. X1

26 28 31 .34 X2 35 37 40.43
:
h

h1

... h2 hs ) h(X

:
X t ) t = h(X .0 t HTSize -1
t . t


:
3-9 .
:3-9
101 X1 X2 X3

)= h(X1

25) 96 = h(X2) .34 = h(X3 X1 25 26 2934


41 . X2 96 97 100 4 11) . )(32 + 96
4 = 101 % 105 = 101 %
X3 34 35 38 43 50 59 . 34
X3 X1
.34

. . HTSize
.
:
HTSize :0 i <j HTSize

568

:
) | . | ( HTSize
:
0 < i - j < HTSize HTSize ) .(j h ) .HTSize | (j+i
j + i HTSize:

.
HTSize .

) () .
(.
.
:

:
:
C++ i

569

) HTSize(

.
X1 X2 ) h(X1) = h(X2

.
. .
.
. ) h(X
:
' h .
4-9 .
:4-9
101 X1 X2 ) 35 = h(X1)h(X2
= 83 h'(X1) = 3 .h'(X2) = 6 X1 3538
570

41 44 47 83 X2 89 95 0 6 ) .
)(0 = 101 % 101 = 101 % (6 * 3 + 83
: :
R HT
R . R R
R . R ' R
R' R . R ' R ' R
.R R
R . ' R
. ' R
. R
.
.
.
.
.
indexStatusList int
: indexStatusList
. i
] indexStatusList [i .1 k
] indexStatusList [k .1- indexStatusList 1-
.1
.12-9

571

:12-9 indexStatusList
12-9 0 1 3 56 8 .
3 .6 1-
3 6 ) indexStatusList .(13-9

:13-9 indexStatusList 36
: :
.
.
indexStatusList
.
:

572

;)void insert (int hashIndex, const elemType& rec


// .
// .
// .rec
// :
// rec
// .
;)void search (int& hashIndex, const elemType& rec, bool& found
//
// rec .
// hashIndex .rec

573

// : rec found true


// hashIndex rec
// found .false
;)bool isItemAtEqual (int hashIndex, const elemType& rec
//
// rec
// .hashIndex
// : true Htable [hashIndex] == rec
// .false
;)void retrieve (int hashIndex, const elemType& rec
// .hashIndex
// :
hashIndex // .rec
;)void remove (int hashIndex, const elemType& rec
// .
// : hashIndex
// rec
// .
;void print ( ) const
// .
;)hashT (int size = 101
//
// : HtableindexStatusList
// indexStatusList =
// size = HTSize .101
;) ( ~ hashT
//
// : HtableindexStatusList
:
// .
;elemType *Htable
; // int *indexStatusList
// .
// .
;int length
// .
;int HTSize
insert .
574

insert :

: ) (:
HT ) .(14-9
j 0 j HTSize 1 ] HT[j .
HTSize .

:14-9
575

:
) X ( H(X) = t .0 tHTSize-1
) ( HT
] .[t X1 X2 ) h(X1) = h(X2
X1 X2
) .
(.
:
R X .
) .h(X ) .t = h(X ]HT [t
.
:
R
R .
.R
:

.
.
.
.
:
.
.
. .
1000 10 ) .
4( . .
1000 10000 1000
. 12000
.
20000 .

576

:
.
1000 . 3000
.
2000 .
.
.
:
:

.
.
:
:
.1

.2

:
:
.1

.2

577

:
:
.1

.2


.1 .
.2 .
.3 .
.4

.
.5 .
.6 n :
.
.7 .
.8 .
.9 .
.10 1024
11 22.
.11 n
.
.12 L .1 < n L . ) SRH(n

x L:

578

.13
.
.

.14

.15 HT
.
.16 X h.X
h ) h(X .
.17
.
.18 X1 X2 X2 X1 ).h(X2) = h(X1
.19 X ) .t = h(X t .
.20 X1 X2 . ) h(X2) = h(X1
. 1 = r 1 .
.21 : ) (
) (.
.22 .
.23
.
.24 t t
.
.25
.

t t t (t + 1) % HTSize ( t + 2+
....%HTSize .(t + j) %HTSize .
.26 .
.27 .
.28 h .
.29 t
t (t + 1) %HTSize

...

579

.
. . .

.30 .
X1 X2 ) h(X2) = h(X1
.
.
. .
.31 .
. ) h(X
:
' h .
.32
.
.33 ) X ( ) t = h(X

0t

. HTSize 1 ) (
].HT [t
.34 X1 X2 ) h(X2) = h(X1
X1 X2 .
.35 R
R
.R
.36:

.37 : :
:
:

.38 : :

580

:
:
.39 : :
:
:

:
.1 :
-

- .
- .
- .
.2 :
100 28 57 46 98 32 45 63

)
(.
-

90

57 -
63 -
120 -
.3 :
110 98 92 85 68 55 49 45 17 10 2

first last middle
.

581

25

49 -
98 -
99 -
.4 orderedArrayListType
.
.5 150 .5

.6 .
.7 .
.8
.9 101
.30
30
. .
.10 101
15 101 116 0217 .
:
-

- .
.11 50 .

.12 .

.13
.14 .
.15 .
.16 1001 850 .
.17 1001 500 .
:
-

582

- .
-
.18 550 .
.
:
-

-
-


) .1 ( .
.
) .2 ( .
.
. orderedArrayListType
. .
.3 .
.
.

. seqOrdSearch
. orderedArrayListType .
.4 :
list 1000.
-

- . insertOrd
.
- :
(1 ) .
(.

583

(2
) .15 (.
- . .2.
.
.5 insertOrd .
.6 removeOrd .
.
.
orderedArrayListType .
.7 search isItemAtEqual retrieve removeprint
hashT " : "
. .
.8 .
. stateData
. setStateInfo
getStateInfo . .
.
. hashT " : "
.
. 15.
.
:

584


10

:
.

.
.
.
9 .
.

.
.
:

. .
.

.
) .
orderedArrayListType (.
.
) (
.
:orderedArrayListType

585

: :
)
( ) ( .

.
.
.1-10

:1-10 10
7
.2-10

:2 -10
) 16 ]( list [0
) 5 ] (list [7 .3-10

:3 -10 ] list [0].list [7


4-10 .

586

:4 -10 ] list [0 ]list [7


] .list [1]list [9
3 .5-10

:5 10
3 .1
) 7 [ (list [3 ) 30 ] (list [1 .6-10

:10-6 ] list [1 ]list [3


] list [1 ] list [3 7-10 .

:7-10 ] list [1 ]list [3


] .list [2] list [9 ) (
.
.
:
-

- .

587

] list [0] list [length 1 .


] .list [1] list [length 1
] list [2] list [length- 1 .
for :

] list [0] list [length 1


] .list [0

]list [1

] list [length 1 ] list [1 .


) .1 1 ( .
.
first last C++
]:list [first] first [last

C++ swap
:

.selectionSort

588

orderedArrayListType :

:1-10
.
orderedArrayListType .orderedArrayListType.h

589

: .
:3 999-
999- 66 32 5 79 36 56 78 12 23 67 34
:8 :
66 32 5 79 36 56 78 12 23 67 34
:12 :
79 78 67 66 56 36 34 32 23 12 5
. 6
insert arrayListType .orderedArrayListType
9 13 print .arrayListType
11 selectionSort orderedArrayListType .
.1 )
( .
if minLocation
swap .selectionSort
.2 .
. 1 .
: :

590

) (9 .
.
. .
.n swap n
1 .(1 n)3
.minLocation k
minLocation .1 k minLocation
) 1 n .(selectionSort minLocation
1 n . minLocation
1 n 2 n .
:

1000 = n

: :
1000 = n
500.000 .
.
.
.8 -10

:8 -10
8 ] list [0] list [1] list [2] list [3 .
] list [3] ... list [0 ) .(9-10
91

:9-10
] list [4 .

list

] [4] < list [3 ] list [4 .


] list [4 ]) list [2 .(10-10

:10-10 ] list [4 ]list [2


] list [4 ] list [2 ] list [4 temp )
.(11-10

:11-10 ] list [4 .temp

] list [3 ] list [4 ] List [2 ]list [3


) .(12-10

592

:12-10 ] list [3 ] list [4 ] list [2 ]list [3


] list [3 ] list [4 ] List [2 ] list [3
.13-10

:13-10 ] list [3 ] list [4 ] list [2 ]list [3


temp ] list [2 14-10 .

:14-10 temp ]list [2


] list [4] ... list [0 ] list [7] ... list [5 .

.

.
.
firstOutOfOrder
593

firstOutOfOrder .
firstOutOfOrder .1
:

.15-10

:15-10
8 .8 = length firstOutOfOrder ) 1
.(16-10

:27-10 lastInOrderfirstOutOfOrder
firstOutOfOrder -> info first -> info
firstOutOfOrder . 2 trailCurrentcurrent
. -10
.28

594

:28-10 trailCurrent.current
firstOutOfOrder trailCurrent .current
.29-10

:29-10 firstOutOfOrder trailCurrent.current

595

C++ linkedInsertionSort .

. 2 3
.

596

: :

:

1-10 .
:1-10 .n


****

****

****
****

.
.
.
L n < n . j k

1 j, k n

] L[j] < L[k ] .L[j] > L [k


. .
j:k ] L[j ] .L[k ] L[j] < L[k
. 30-10 ) .3 30-10
(.

597

:30-10
.
x y x .y
L .
.
.
n n > 0 ! .n
! n L ! n
.
.
.
: L n . L
.


.
..
: :


) .O(n2

. .
.

. :
) (1
}
- .
- .
- .
- .
{

598

lowerSublist
upperSublist .
.
.
. 4
.

. .
.
.
: .

. .31-10

:31-10
.
.
.
50 .32-10

:32-10
32-10
.
.
) (:
.1 .

599

smallIndex .
smallIndex .
.2 ) (:

- .smallIndex
- .smallIndex
.3 .smallIndex
2 for .
1 . 2
) .33-10
.(list

:33-10 2
33-10 .
.
smallIndex index

. 2 ) ](list [index
smallIndex ] list [index
] .list [smallIndex .2
.34-10

:34-10

600

34-10 .6
) .35-10 35-10
52 (32

:35-10
2 .36-10

:36-10 2
36-10
.index ] > list [index list
] [index . smallIndex
] list [smallIndex ] .list [index
) .37-10 11 (.96

:37-10 11
.38 -10

601

:38-10 58
38 -10 ] list [index 58 .
] list [index 58
. 58
.39-10

:39 -10 58 .

) 2 ( 40-10
.

:40-10 .
3 52
52 .45 .41-10

:41-10 52 45
41-10 1 2 3
.
.
602



.
smallIndex.index
partition
. partition
.
.

partition .
swap ) swap
(.


.
.
.

603

partition
.
recQuickSort
:

quickSort recQuickSort
.

. 5
.
: :
2-10 ) .n
(
:2-10 .n

***

***
***

***

: :

. ) .O(n2
.


.
.
604

.
.
.

.
.
:
38 30 48 62 45 18 28 35 :
:
45 18 28 35 :
38 30 48 62 :
) (
. . :
45 35 28 18 :
62 48 38 30 :
.
42-10 .

605

:42-10
42-10
.
:
1
}
. .
. .
. .
. .
{

.
.
:
.
.
.
:
.

.
.43-10

:43-10
middle .current middle
. current
) .

606

1 . current
(.NULL .44-10

middle :44-10 current


middle current . current
current current .
middle current . current
NULL middle .
middle ) 25 .(45-10

middle :45-10
. middle
.middle middle .NULL 46-10
.

:46-10
C++ :divideList

607


.
.
:

.
.
.47-10 first1
first2 .

:47-10

608

.
newHead .
lastSmall .
. 48 -10
47-10 newHead lastSmall .first1

:48 -10 newHead lastSmall first1


48 -10 first1
. first1 first2

. 48 -10 49-10
.

:49-10 20

609

.
first1 first2 .
first1 first2 .NULL first1 NULL
.

first2 NULL
.
C++ mergeList .
.mergeList

610

recMergeSort divideList
mergeList .
.recMergeSort

mergeSort
) .orderedLinkedListType divideList merge reMergeSort
orderedLinkedListType
.(mergeSort mergeSort recMergeSort
first . mergeSort:

. 8
.

611

: :
L n .n > 0 ) A(n
) W(n .L
:

: :

.

.
.
:
k ) 2k + 1
( ) 2k + 2 (.
C++ k
k + 1 .
.50-10

:50-10
50-10 .
:

. k 1 k
) 2k ( 1 2k
) 1 + 2k ( 2k
.
51-10 50-10

612

:51-10 50-10
51-10 50-10 .

.
.
buildHeap
.
:
.
: length .

= index

.1 2 / length ] list [index


. ]list [length 1] ... list [index + 1
.
] list [index .
. list
] [index 1 .
: ] list [a
] list [b ] list [c ].list [a
] list [b ] list [c . ] list [c ] list [b
. largerIndex ) largerIndex b (c
] list [a ] .list[largerIndex ] list [a] < list [largerIndex list
] [a ] list [largerIndex ] list [a
.
] List [a] < list [largerIndex ] list [a

list

] .[largerIndex

613

] list [largerIndex . 1 2
] list [largerIndex
.
.
52-10 .list

:52-10 list
53-10 .52-10

:53-10 52-10
56 .56
11 .11
4 = 1 5 = 1 2/11 = 1 2/n . list
] 56 = [4 ] list [4 ] list [4 * 2 + 1 ] list [4 * 2 + 2 ] list [9] .list [10
] list [9 ] .list [10 ]list [4
:
.1 ] list [9] list [10 ] .list [4
] list [10 ].list [9
.2 .
. ] List [4] < list [10 ] list [4 list
].[10
.3 ] list [10 .3
54-10 .

614

:54-10 ] list [4 ]list [10


] list [3 70
) .55-10
(3

:55-10 1 2 3 ]list [3
] list [2 72
. 56-10 ) .
(.

:56-10 1 2 3 ]list [2

615

] list [1 .60
1 .2 list [1] = 60 < list [3] = 92 ] list [1 ] list [3
.57-10

:57 -10 ] list [1 ]list [3


] list [1 ] list [3 list
] [3 60 . .
3 60 .60
.58-10

:58 -10 ]list [3


] list [1 92 )
.(58 -10
] list [0 15
.59-10

:59-10 1 2 ]list [0

616

] list [1 5
3 ) . 1
2 ] (.list [1 ] list [1 ]list [3
.70 .60-10

:60-10 1 2 ]list [1
] list [3 15
. 1 2
] .list [3 ] list [3 ] list [7 .60 -10
61 .

:61-10 ]list [3
) (61-10
.

:
.
.
low high
. ].list [low
C++:

617

swap ** Line . swap



. while
] list [low .
.temp
.temp
temp .
heapify
.
.

618

heapify buildHeap .

.
.
.62-10

619

:62-10

. .
) ( .
.63-10

:63-10

] .list [9] ... list [0
. heapify
. :
;)heapify (list, 0, 9
.64-10

:64-10 ;)heapify (list, 0, 9


] .List [9] ... list [0
] list [0 ] list [9 ]list [0
.list [8] ... .
C++ :

620

. 9
.
: :
L n .n > 0
) L heapsort
(buildHeap
L

.
.


.
.

.
) .O(n2
.

621

) (:
8 .
. 8
.
.
.
heapify .
.
heapify ) (addQueue
) (deleteQueue .
.
:
:
.1 ) .
(.
.2 . :
) while (
.
.
:

:
.1 .
.2 .1
.3 .
.
.

622

: :

.
. .
.
1 2 3 .4
.
:

:
------------------------------ -----------------------------
1 2 3 4

--------- -----------------

-------- ---------

--------

--------

272

272

25

71

156

97

349

110

158

268

.
.
.
: :
:
.
.
.
: candData.txt
.
.
voteData.txt :

623

voteData.txt
. .
:
1

23

56

25

23

.
.
.
23 .1
: :
.
: .
:

.
.
. candidateType
. .
. ) 6-1 (1 personType
. personType .
) (2 personType
.
/.
candidateType .personType
personType
personType . personType
: firstName lastName
.

624

personType .
personType ) 65-10 (.

625

:65-10 personType
= = >>
. 11 .

:candidateType
.
.
.
.
candidateType .personType

626

personType
.candidateType
.candidateType
orderedArrayListType
. .
) ( candidateType
.
.

candidateType .
: candidateType
candidateType ) personType .(66-10

627

:66-10 candidateType
candidateType .

628

.setVotes
1 .
1 . setVotes
:

.
. updateVotesByRegion:

calculateTotalVotes getTotalVotes printData


getName .

629

candidateType .
.
.personType = =
. .11

candidateType .
.11
:
candidateType .
candidateList
.candidateType
candData.txt .candidateList .candidateList
voteData.txt .

. :
.1 .candidateList
.2 .candidateList
.3 .
.4 .
candidateList :orderedArrayListType

630

67-10 .candidateList list


:candidateType

candidateList :67-10
67-10 votesByRegion totalVotes
.candidateType
candidateList .68-10

:68-10 candidateList
631

:fillNames
.candidateList
. candData.txt .main
candidateList .fillNames
candidateList .
temp candidateType ) inserAt
(ArrayListType .candidateList
fillNames :

fillNames 69-10 .candidateList

632

:69-10 candidateList fillNames


:
list candidateList
) ( .
candidateList orderedArrayListType
.
. :
;) ( candidateList.selectionSort
candidateList .70 -10

:70-10 candidateList ;) ( candidateList.selectionSort


:
. voteData.txt :

voteData.txt ) list
(candidateList
.regionNumber
633

votesByRegion .list
list .candidateList

list .
retrieveAt .
replaceAt
. :
35 2
35 .2
candidateList .71-10

:71-10 candidateList 35 2
) .(72-10

634

:72-10 temp
) .2 = 2 = (.35

temp .73-10

:73-10 temp

temp ) list .(74-10

candidateList :74-10 .temp

635

list candidateList
.
binarySearch orderedArrayListType
.list processVotes )
11 (.
:
.
. votesByRegion
candidateType list
.candidateList retriveAt

.candidateList :

75-10 candidateList
.addVotes

636

candidateList :75-10 addVotes

:
.
:

printResults . sumVotes
largestVotes
winLoc
.list temp .candidateType
:
.1 sumVotes largestVotes winLoc .
.2 :
-

.temp

- .
- .sumVotes

.3 .
printResults . 11
.
) (:

637

// fillNamesaddVotes
// printHeading .
// processVotes printResults.
) : personType candidateType
processVotes printResults . ) .
(.11
--------------------- ---------------------------

1 2 3 4

--------- -----------------

-------- ---------

--------

--------

272

272

25

71

156

97

349

638

158
110

34
75

141
112

56
285

: 498 :
2017 :
:
candData.txt






voteData.txt
34 2
56 1
56 2
78 1
29 4
78 4
63 2
23 1
56 2
25 1
23 4
12 4
134 3
82 4
67 3
67 2
67 3
23 4
56 1
35 2
27 1
34 2
75 1
23 4
89 4
23 1
89 3
89 3

0
134
156
0

639

0
0
89
46

268
243
498
387

67 1

37 2
89 4
78 2
87 1
90 1
56 4


.1 ) (
) ( .
.2 n n > 0
(1 n) 3 .
.3 n n > 0

.4 L n . L
.

.5 .
.6


.
.7 .
.8

.9 .
.10 .
.

.11

.12
k ) 1 + 2k
( ) 2 + 2k (.

640

.13 .buildHeap
.
.14 L n .n > 0
.

L
L

.1 :
20 55 10 21 18 5
. 10

.2 :
20 5 40 31 28 7
. 5

.3 :
15 58 32 71 12 30 25 10 21 18 28

6
6 .for
.4 ) ( .
.
3 35 83 75 48 22 61 32 20 15 9 11 8 18

.5 .
.
.6 :
36 25 58 100 5 95 64 48 55 65 22 80 54 38 16
.
.
-

641

- .
.7 :
35 27 17 14 72 47 37 50 57 64 82 16 40 18
.
.
-

- .
.8 buildHeap
.
20 7 37 34 59 95 87 63 53 92 80 65 42 58 82 50 52 81 78 47
.9 buildHeap
.
5 28 14 35 17 45 50 65 60 20 30 76 82 72 47 94 85 100
) . heapify
( . .
.10 orderedArrayListType )
(9 .
.10 .11 orderedArrayListType )
(5 .

:
.1 .
.2
.
.3 .
.4
.
.5 .
(C.A.R.Hoare) .6 L .n
k L 0 < k < n 1 L .
C++ kTheSmallestItem
k L L .

642

.7 10.000 :
-

- .
- .
20 .
-
. 20
.
-
x .clock_t

=x

;) ( clock .x
.
.
ctime clock_t .clock
.
.8 .
.9 .
.10 .
.
. )(.
. .
.11 . personType
.
. candidateType
.
. processVotes printResults
.
.
.
.12 candidateType
.calculateTotalVotes

643

. ) updateVotesByRegion (candidateType
.
. addVotes
. .updateVotesByRegion
.13 candidateList
orderedArrayListType .
.
candidateList candidateList
. list
CandidateList list .
:
candidateListType .orderedArrayListType

candidateListType orderedArrayListType list


) orderedArrayListType
(arrayListType
.candidateListType
candidateListType
.candidateListType

644


11

:
.
.
.
.
.
.

. .

.
. )
(
.
.
.
.
.
.

645

:

.
.
: T :
(1 .
(2 L1 R1
T .
L1 (3 R1 .
. T .A

.A

. B C

. B A C
.A A B.C
.
) (
. ) (
. .
) ( . B

.
.
.
1-11 . .A

.B C .
.

D.

646

:1-11
1-11 A B A .C F
H .
1-11 5-11 .
:1-11
. .2-11

:2-11
:2-11
= A
=
=
:2-11
. .3-11

647

:3-11
:3-11
= A
= }{B
=
= B
=
=
:3-11
. .4-11

:4-11
:4-11
= A
=
= }{C
= C
=
=
:4-11
. .5-11

648

:5-11
:5 -11
= A
= }{B
= }{C
= B
=
=
= C
=
=
:5-11
. .6-11

:6-11
.

. llink .rlink llink
rlink
.
:

649

:
.info
.llink
.rlink

.nodeType
.7-11

.
.
.
.
. U V
.T U V U .V x
:

y
-
-

.n ... 2 1 = i


.
: .
.1
650

: .
p . C++
height .
.height
height .
.
.

. ) (
)( .
) p :(p

. :

height max .
max.
.
:
.

.
.
.
.

651

copyTree
.
) " "(.

copyTree .
:
.


. ) (7-11
.

.
.

:
.
.
.
:
:
.
.
.
652

:
:
.1 .
.2 .
.3 .
:
:
.1 .
.2 .
.3 .
.
.
.
.
C++
.8-11 . "
"

.

:8 -11
8-11 ) root
.(A .A
.

.1 A
.2 .A
.3 A

653

2 .1
.1 A
.B

1- 1

2- 1

.B

3- 1

=
.

1-1 .2-1
1- 1

B .
1-1 .2-1

2- 1

.B B .
.B 2-1 .3-1

3- 1

B
.D

1-3-1 D

= .

2-3-1 .D
3-3-1 D

= .

1-3-1 D
. 1-3-1 2-3-1
2-3-1 D D . 2-3-1
.3-3-1
3-3-1 D

3-3-1.
3-1 1-1 2-1 3-1 1
.2
.2 A A . 2
.3 A
.C

.3

654

1-3 C

= .

2-3 .C
3-3 C

1-3 C .
1-3 2-3
2-3 C C . 2-3 -3
.3
3-3 C . -3
3.
3 .
.
B D A C :
:
A B C D :
D B C A :

.
.
.
) .
(.
:

655


.inorder
inorder:
; )inorder (root
.
.

:

. .
.
.1 .
.2 .
.3 .
.4 .
.5 .
.6 .
.7 .
.8 .
.9 .

656


.
.
.

. .
:

657

658

binaryTreeType
. binaryTreeType .

.
binaryTreeType
.
.
inorderTraversal inorder root .
:

659

:myTree
binaryTreeType root
.
.binaryTreeType
root NULL isEmpty
:

root .NULL
:

660

661

nodeCount leavesCount ) . 1
2 (.
copyTree destroy destroyTree
.
copyTree
.binaryTreeType


. delete .
destroy:

destroyTree destroy root


.destroy destroyTree:

662


. binaryTreeType
.
copyTree
.

. binaryTreeType
.
destroy .

.
.copyTree
:

663

:

.
.9-11

:9-11
50 .
.

.
.

.
.10-11

664

:10-11
10-11 :
.
.
10-11 .

58

. . 58
58 .60 60 58

> 58

60 58 .
58 .
.50
. 50 < 58
.58 .58

.
.
10-11
)
(.
: T :

665

T .1 .
T .2

T .
.3
.
.4


) (iiii ) .(iiii
) ( ) (.
:
.1 .
.2 .
.3 .
.4 .
.5 .
.6 .
.7 .
.8 .
.9 .
.
.

. .
.
:

666

.
:
search .
true .false root
. root
current
. current .root

. .true
) llink (
) rlink ( .
.
.
:

667

C++:

:
insert .
.
.
.search
current trailCurrent .current
.
trailCurrent .
insertItem .insert
:

668

. ) insertItem ( .
.NULL
. root NULL root
.

C++:

669

:
deleteNode .
.
.
.11-11

670

:11-11
) (
. :
:1
. 45 .
:2
.
40 .
:3
. 80
.
:4 .
50 .
:1 45 .11-11
.45
45 NULL
. 12-11
.

671

:12-11 45
:2 30 .11-11

. 30
30 30

35

.30 13-11 .

:13-11 30
:3 80 .11-11
80 . 80
70 .80 14-11 .

672

:14-11 80
:4 50 .11-11 50
.
2 3 . 3
. 50
.48 50
.50 .
. 48
.50 .
3 ) .
(. 50
11-11
.15-11

673

:15-11 50
.
:
.1 ) ( .
.2 .
.deleteFromTree

.

.
deleteFromTree .
35 .
trailCurrent 30
.35 deleteFromTree:

674

deleteFromTree
:

C++ .deleteFromTree

675

.deleteNode deleteNode
. deleteItem
. deleteItem
deleteNode deleteFromTree . deleteNode
.

676

:
. T n
.n > 0 x .T
.T . T
T .16-11

:16-11
T T .

n.
. .
n ! n .
! n . ) S(n
) U(n .
x T
x T . x T
x .T
:

677

) (1-11) (2-11 :

.
: T n .n > 0
T

:
:
.
.
.
.
.

.
:

.
. 17-11
.28

678

:17-11 28

.NULL
.
.
.
.
. .
:

679

:

.

. :

680

:

.


.

.
) (
1 2
.
.
.
:

681

)( :
) 1 (2 . C++
) . 6 (.
:

.
. .

.


.
.
. .

.
.
C++ .
.
:

1 fParamFunc1 void
int . 2 fParamFunc2 void
elemType .
.binaryTreeType
. .
:binaryTreeType

682

;) ) &void inorderTraversal (void (*visit) (elemType


// .
//
// .

;) ) &void inorder (nodeType<elemType> *p, void (*visit) (elemType


// .
// p
//
// .
:

:
;)(*visit) (p -> info
inorder elemType
.visit
6-11 .
:6-11

683


. .
bSearchTreeType binaryTreeType
. binaryTreeType
.bSearchTreeType

684

: .
:3 999-
999- 66 90 12 45 34 65 23 87 56
:8 90 87 66 65 56 45 34 23 12 :
:10 4 :
*********** :11 **************
:13 :
180 174 132 130 112 90 68 46 24
:15 4 :
. 1 treeRoot
.int 4 7 .
9 inorderTraversal treeRoot
.treeRoot inorderTraversal 9 ) print
.(17 print 9
.treeNode 10 .
12 inorderTraversal
.treeRoot 12 inorderTraversal update
) .(11 update .
12 .
14 15 .
) AVL (:
.
.
.
. .
.
) AVL (
. AVL
1962 .
:

685

: :
.1 .
.2 .
18 -11 .

:18 -11
T x .T T
x
.x
T h T
. 2
.
.
: ) AVL ( :
.1 1 .
.2 .AVL
19-11 20-11 AVL .AVL

686

:19-11 .AVL

:20-11 .AVL

687

x .

.x
: T AVL x .T

x .AVL:
.1

x .

.2

x .

.3

x .

: x ) bf(x

.
.
.

x T .AVL:
.1 x )1- = bf(x
.2 x )0 = bf(x
.3 x )1 = bf(x
: x . x
.1

x AVL .x
.
. AVL:

AVL AVL
.
AVL
.
AVL .

688

) ( AVL .AVL
.
:AVL
AVL
. AVL
AVL
.
.
. .AVL
.
.AVL
.
.AVL )
( .
.
21-11 32-11
)=(
)>( 1- )<(
.1
AVL .21-11

:21-11 AVL 90
90 .AVL
.90 . 90
.22-11

689

:22-11 21-11 .90 90



22-11 .AVL
.80 80 .
) ( 80 ) 1
( . .70 70 .1
70
70 .AVL )
.(70 AVL
.23-11

:23-11 21-11 90
23-11 .AVL
AVL .24-11

690

:24-11 AVL 75
75 AVL .24-11
. .
75 .25-11

:25-11 24-11 75 75

75 . 80

.1-

80 .AVL .70
70 .AVL
80
70 ) .26-11
" .("AVL

691

:26-11 AVL 24-11 75


.75
23-11 26-11
.
.
.
AVL .27-11

:27-11 AVL 95
95 .AVL 95
.28 -11

692

:28 -11 27-11 95 95



95 90 80 75 .AVL
) ( .
.AVL
50 1
.
.50 50
.29-11

:29-11 27-11 95

693

)( .
AVL .30-11

:30-11 AVL 88
88 .30-11
.31-11

:30-11 30-11 88 88

694

. 85.90
80 .
.32-11

:32-11 AVL 30-11 88


.
.


) . ( .
.
:AVL
.
. .x
x
x .
x x
x .
:1 .33-11

695

:33-11 b
33-11 T1 T2 T3 .h
T1 T1 .1
a AVL .
. :
T1 .a
T2 .a
T2 .b
:
.1 ) T2 (a .b
.2 b .a
.3 a -11
.33
:2 .1 .34-11

696

:34-11 .a
:3 .35-11

:35-11 : a .c
35-11 .
.
T2 T3 . )
(:
T3 .c
T3 .b
T2 .b
T2 .a
a b .AVL
c.
c 1- a 1 .
. a
.c
. a
.c a .a
c .c 35-11
697

) ( . 36-11
.

:36-11 a c
:4 .3 .37-11

:37-11 : c a
.

698

.x
x .
.1 x x
.
-

) .x
x .
x

(.x
- ) .x
x .
x

(.x
.2 x x
. x 1-
y .x y
.1 y .
.x ) y y
( .x
.
C++ .
.

699

C++
) balanceFromLeft ( ) balanceFromRight (
.
. ) rotateToLeft (
) rotateToRight (
. balanceFromLeft
700

.
balanceFromRight .

.balanceFromRight

701

.insertIntoAVL insertIntoAVL
.AVL AVL
.
:insertIntoAVL
.1 .
.2 .
.3 .
.4
. .
4

702

insertIntoAVL ) . (.
. insertIntoAVL bool isTaller
.

703

insertIntoAVL AVL .
. ) 37-11 (45-11
. )=(
)>( 1-
)<( .1
AVL . 40 AVL .

.38-11

:38-11 AVL 40
30 .AVL .39-11

:39-11 AVL 30
30 40
40 . 40 .1-
20 .AVL .40-11

:40-11 AVL 20

704

20 .40 40
.
60 .AVL .41-11

:41-11 AVL 60
60 40 .30
.50 .42-11

:42-11 AVL 50
50 .40
.40
.80 .43-11

705

:43-11 AVL 80
80 .30 .15 -11
.44

:44-11 AVL 15
15
20 30.50
.28 .45-11

:45-11 AVL 28
28
.20
.25 25 .30 46-11
.

706

:46-11 AVL 25
46-11 20
.30
insertIntoAVL
:AVL

AVL .
9 ) . AVL

AVL (.binaryTreeType

707

:AVL
AVL .
:
:1 .
:2 .
:3 .
:4 .
1 3 .4

.4
x .
4 2

y .x

y x y . y
.
.
.AVL AVL ) (
.

.
) .
shorter

(. p

. .p
.1 p p
p
.p shorter .false
.2 p .p
p shorter .true
.3 p p
q p .
-

q p shorter
.false

- q p p
shorter .true

708

- p q ) p
q .(p shorter .true
: :AVL
AVL .h

AVL h

.
.:

AVL h

1 h .2 h

1 h
1

.2 h

AVL h

AVL .1 h

2 h AVL h
.2

709

AVL n
. n
AVL %44 .
AVL .
AVL %4 .
: ) (:
5 .
) ( .
.
. ) (
.
.
. 5
.
:
5 .

.
.
. videoType .
.

710

videoType .5
:

711

:
videoBinaryTree
.bSearchTreeType videoBinaryTree :

712

;)bool videoSearch (string title


//
//
title // .
// : true
// .false
;)bool isVideoAvailable (string title
//
// .
// : true
// .false
;)void videoChechOut (string title
// .
713

// : .1
;)void videoCheckIn (string title
// .
// : .1
;)bool videoCheckTitle (string title
//
// .
// : true
// .false

;)void videoUpdateInStock (string title, int num

714

//
// .num title
// .
// : = num +
;)void videoSetCopiesInStock (string title, int num
// .
// title
// num
// .
// : = .num
;) ( void videoPrintTitle
// .
:
void searchVideoList (string title, bool& found,
;)nodeType<videoType>* &current
//
// found
// true .false
// current
// .
;)void inorderTitle (nodeType<videoType> *p
// .
videoBinaryTree .5
searchVideoList inorderTitle) .videoPrintTitle
10 (.
searchVideoList
. true
false .
searchVideoList .videoBinaryTree
.
715

. searchVideoList
.videoBinaryTree
:

inorderTitle
.
. :

716

videoprintTitle inordertitle
. :

:
. .
videoBinaryTree videoBinaryTree.h.

717

718

19

720


.1 .

.
.2 .
.3 .
.4 U V U .V
.5 x y
) (

)(

.n ... 12

= i

.
.6 .
.7 .1
.8 .
.9 :
-

- .
- .
.10 :
-

- .
- .
.11 :
-

- .
- .
.12 T :
-

T .

T -

T .

721

-
.
-

.13
.
.14 :
-

- .
.15 ) AVL ( :
-

- .AVL
.16 x .

.x
.17 T AVL x .T

.18 x AVL :T
-

x .

x .

x .

.19 x ) bf(x

.
.

.20 x AVL .T:


-

x .1- = x

- x = x.
- x .1 = x
.21 x . x
x .1
.22 x AVL
.
.23 AVL .
.x

722

x
.
x
.

.1 :
-

- .
-
.
- .
.2 14 . .
47-11 3 .8

:47-11 3 8
.3

.A

.4

.A

.5

.B

.6 .
.7 .
.8 .

723

48-11 9 .13

:48 -11 9 13
.9 80 .79
.10 35 .
insert .35 .35
.11 52 .
.12 40 .
.13 80 58 .
.14 .
.
.15 :
ABCDEFGHIJKLM :
CEDFBAHJIKGML :
.

724

.16
.
.17 100 AVL .49-11
.AVL

:49-11 AVL 17
.18 45 AVL .50-11
.AVL

:50-11 AVL 18
.19 42 AVL .51-11
.AVL

725

:51-11 AVL 19
.20 ) ( AVL .
AVL .
29 5 19 34 48 46 31 39 24


.1 nodeCount .
binaryTreeType .
.2 leavesCount
.
binaryTreeType .
.3 swapSubtress
. binaryTreeType .
.4 singleParent .
binaryTreeType ) . :
(.
.5 .
.6 . .

726

. .
.7
.
.8
.
.9 . AVL ) .
(.
. ) (.
. .AVL
.10 videoBinaryTree
.
).11 ( 14 5
.
customerTreeType
. customerTreeType
bSearchTreeType .
nodeCount binaryTreeType
.
).12 (
10
11 .
nodeCount binaryTreeType .

727


12

:
.
.
.
.
.
.

.
.
.

728

:
1736 . ) (
)( . .1-12

:1-12
) A B C (D .
.1-12 a b c d e f.g
:
1736
2-12
) (.

:2-12

729

.

.
.
.

:
. X
. a X ) .X a " " " "(
y X y .X Y
X ) .X Y " " " " (.
A B B A A B B A
= }) .{x | x A, x B " " " "( . A B B A
A B {x | x A or x = B A
}) . B " " " "( . A B B A
A B = B A
G ) G = (V, E V
G .V V E E .V E
.
) V(G ) E(G .G )E(G
G G
. ) (u, v ) (v,u .
G . H G )V(H) V(G
) E(H) E(G H G H
.G
. .
.
.
:1-12

730

3-12 .

:3-12
:2-12
4-12 .

:4-12
4-12:

731

G . u v .G u v
.(u, v) E ) e = (u, v .G e
u .v . e1e2
e1 e2 .
. u v
un u2 u1 u = u1 un = v ) (ui, ui + 1 n ... 2 1= i
.1 u v u .v
. G
. G
. .G
G u v .G u v

)(u, v

E u v v .u G
. G
.G
.4-12 G1 5-4-1 1
.5 .G1 G2 1-2-1 . G3

3-4-2-1-0

3 10-8-6-5-1 1 .10
.G3
:

. ) ( .
: .
:
G n .n > 0
n n ) (i, j

= ) .V(G
1

) (i, j . :

:3-12
.4-12 G1
G2 G3 :

732

:
G n .n > 0

= ) .V(G

v
u ) .E(G) (v, u n A n
] A [i

vertex . vertex
.i
:4-12
.4-12 5-12

733

:5-12 G2 4-12
6-12

:6-12 G3 4-12
:

.
:
.1
.
.2 .
.3 .
.4 .
.5 .

.

734

.
) ( . v v
) ( .v
linkedListType

.5



. linkedListType
) . print
(. ) linkedListType (
. .
.linkedListGraph :

getAdjacentVertices .

.
735

) (:
. )
( . :


. 100 int :
.listType
) (int 100 .
.
) maxsize ( length
)(.
.
.
:

.
:

736

const int infinity = 10000000


//
//
// .
) ( bool isEmpty
// .
// true
// .false
) ( void createGraph
// .
// .
737

) ( void clearGraph
//
// .
;void printGraph ( ) const
// .
;) ( graphType
//
// :
= gSize // .size = maxSize
;) ( -graphType
//
// :
// .

;int maxSize
//
;int gSize
//
;]linkedListGraph<vType> graph [size
// ) (.
C++
n .1 n ... 1 0 .

.

738

graphType .
gSize .
isEmpty :

creatGraph .
.
. :
5
999- ... 4 2 0
999- ... 8 6 3 1
...

) (
.999-
createGraph:

739

clearGraph
.

printGraph .

740

:
.
.
.

. .

) ( .
. ) ( .
.

. .
. bool visited
.
:
. :
v
v
v

741

G3 .4-12 7-12
.

:7-12 G3
G3 7-12:
9 7 10 8 6 5 3 4 2 1 0
:
.1 v .
.2 .
.3 u v
v
u
. dft .
visited .

742

depthFirstTraversal
.

depthFirstTraversal .
dftAtVertex :

:
)
( . i
.i + 1
) G3 ( 7-12:
9 7 10 8 4 6 3 2 5 1 0
G3 .
1 .5
1 2 .3 5
743

.6 2
.

.
.
. :
. v
v
v // .v
. v .
.
.1. u .
.2. .u
.3. w u
w
.1.3. w
.2.3. w
C++ breadthFirstTraversal :

744

graphType:

) ( bool isEmpty

745

// .
// true
// .false

) ( void createGraph
// .
// .

746

) ( void clearGraph
//
// .
;void printGraph ( ) const
// .
;) ( void depthFirstTraversal
// .
;)void dftAtVertex (vType vertex
//
// .vertex
;) ( void breadthFirstTraversal
// .
;) ( graphType
//
// :
= gSize // .size = maxSize
;) ( -graphType
//
// :
// .
:
; // int maxSize
;int gSize

//

747

;]linkedListGraph<vType> graph [size

//

) (.
:
;)] [ void dft (vType v, bool visited
//
// .
C++
) ( .graphType
:
.
.
.
.
.
.
G u v G p G u .v

P P v u .P
G . .

) ( .

.

.
G n .n > 0
n n:

748

= ) . V(G W

.
) graphType (
creatWeightedGraph .
.weightedGraphType
.
weightedGraphType:

:
;) ( void createWeightedGraph
// .
;)void shortestPath (vType vertex
//
// .
;)void printShortestDistance (vType vertex
//
// .

749

:
;]double weights [size] [size

// .

;] // double smallestWeight [size .


createWeightGraphs . .
:
) vertex ( .
:
.1 smallestWeight
.2 ] = smallestWeight [vertex.
.3 v .
.4 v )( .
.5 w G w

(v,

) w w v w
+ v ).(v, w
n 3 5 1 n.
5-12 ) . bool weightFound
.
weightFound true
(.false
:5-12
G .8-12

:8-12 G

750

G . . 1
2 ) .9-12 9-12 (.

:9-12 12
3 true ] .weightFound [3

3-1-0

14 1 .1-0 smallestWeight
] [1 .14 10-12 ) .
(.

:10-12 3 45
751

4 smallestWeight
weightFound .false
] weightFound [4 .true 1-4-0 13
1 .14 ] smallestWeight [1
] .smallestWeight [2 11-12 .

:11-12 3 45
.2 ] weightFound [2 .true -0
1-2-4 10 ) 1 .(13
] .smallestWeight [1 12-12 .

752

:12-12 3 45
1 . 13-12
.

:13-12 3 45
C++ shortestPath :

753

shortestPath .
.
printShortestDistance:

:
14-12
. .

754

:14-12

) ( . ) 15-12( )( )(
.

:15-12 14-12
) 15-12( 33

15-12

)( 28 ) 15-12( .25
) 15-12( .
15-12 .14-12
.15-12
15-12 14-12
755

. .
15-12
. .
.
)( T u v T
u .v .
T T . T
T ) W(T .T
T G T G )= V(T
) V(G G .T
G .14-12 15-12
.G :
: G G.

.
G . G
.

. .

. .
.
n .

G )= V(G

. T . ) V(T )E(T
. ) V(T ) V(T
T .
).E(T

756

) : n :(G

G ) 16-12
.(14-12

:16-12 G
N G .T .0
1 2 ) V(T) E(T N .17-12

757

:17-12 G) V(T) E(T N 12


2-3 :

)(1 0

)( 2 0

)( 3 0

) (3 0 . 3 ) V(T )0
(3 ) .E(T 18 -12 ) V(T) E(T.N
) (T

:18 -12 G) V(T) E(T N 3


2-3 :

)( 1 0

)( 2 0

)( 4 3

) (2 0 . 2 ) V(T )0
(2 ) .E(T 19 -12 ) V(T) E(T.N

758

:19 -12 G) V(T) E(T N 3


2-3 :

)( 1 0

)( 5 2

)( 6 2

)( 4 3

) (6 2 . 6 ) V(T )2
(6 ) .E(T 20 -12 ) V(T) E(T.N
) (T

:20 -12 G) V(T) E(T N 3

759

2-3 :

)( 1 0

)( 5 2

)( 4 3

)( 1 6

) (1 6 . 1 ) V(T
) (1 6 ) .E(T 21-12 ) V(T) E(T.N
) (T

:21-12 G) V(T) E(G N 3


2-3 :

)( 4 1

)( 5 2

)( 4 3

) (4 1 . 4 ) V(T
) (4 1 ) .E(T 22-12 ) V(T) E(T.N
) (T

760

:22-12 G) V(T) E(G N 3


2-3 :

)( 5 2

)( 5 4

10

) (5 2 . 5 ) V(T
) (5 2 ) .E(T 23-12 ) V(T) E(T.N
) (T

:23-12 G) V(T) E(G N 3

761

G .25

.
msvt bool ] msvt [j true
T false . ) edges (

. )

edges [j] = k

. edgeWeights ] edgeWeights [j )

(.

;) ( void createSpanningGraph
// .
;)void minimalSpanning (vType sVertex
//
// .edgeWeights
;) ( void printTreeAndWeight
//
// .
createSpanningGraph .
.
C++ minimalSpanning :
762

minimalSpanning .for

. 5 .

printTreeAndWeight .

763

:

. 2
.1
.

u v
.v



.
. :
G )= V(G

n 1 k n

.n > 0 )V(G

j < k .

764

kj 1j

.
. .
:
u G u .
v G v .
) topologicalOrder n (

G . u v ] v = topologicalOrder [j
] u = topologicalOrder k .j < k

. .
7
.
) graphType (
. .topologicalOrderT
:

.bfTopOrder
:

) ( .
.
y v
. .predCount
] predCount [j

] predCount [k . :

765

.1 predCount ] predCount [i
.
.2 queue

] predCount [k .

) (.
.3
3.1 u .
3.2 u ] topologicalOrder [topIndex
.topIndex
3.3 w :u
3.3.1 w .1
3.3.2 w w .
G3 7-12 . G3
:
10 8 3 6 4 5 2 7 1 9 0 :
.G3
1 2 predCount topologicalOrder queue
) .24-12 (.

:24-12 predCount topologicalOrder queue 12

766

3 .
:3 :1 1-3 u . 2-3
u .topologicalOrder
. 3-3
1
. 0 1 .5 1
5 .1 .
3 predCount topologicalOrder queue
.25-12

:25-12 predCount topologicalOrder queue


3
:3 :2 . 1-3 u . 9 -3
2 u .topologicalOrder
1 . 3-3
1 1 9
. 9 4 7 .10

767

7 4 10 .1 7 .
3 predCount topologicalOrder queue
.26-12

:26-12 predCount topologicalOrder queue


3
:3 :3 . 1-3 u . 1
2-3 u .topologicalOrder
1 2 . 3-3
1 1 1
. 1 2 3 .5
2 5 3 .2 2 5
. 3 predCount
topologicalOrder queue .27-12

768

:27-12 predCount topologicalOrder queue


3
3 predCounttopologicalOrder
queue .28-12

769

:28-12 predCount topologicalOrder queue 3



28-12 topologicalOrder
.G3
C++ :

770

771


.1 G ) G = (V, E V
G V V E .
.2 ) G = (V, E E .
.3 ) G = (V, E E .
.4 G . H G
H G H .G
.5 u v
.
.6 ) e = (u, v .G e u
.v
.7 .
.8 e1 e2
e1 e2 .
.9 .
.10 u v un ... u2 u1 u = u1 un
= v ) ui (ui + 1 .1 n .... 2 1 = i
.11 u v u .v
.12 .
.13 G .
.14 G
.
.15 .G
.16 u v .G u v
) E (u, v u v v .u
.17 G G.
.18 G n .n > 0 )= V(G

n n ) (i, j

).(i, j

772

.19 v
u ).E(G) (v, u
.20 .
.21 .
.22
.
.23 .
.24 P P
v u .P
.25 )( T u v T
u .v
.26 .
.27 T . T T .
.28 T T ) W(T
.T
.29 T G T G
) V(T) = V(G G .T
.30 G )= V(G
) V(G
k 1 j n 1 k n

.n > 0

29-12 1 .4

773

j < k

:29-12 1 4
.1 .
.2 .
.3 .
.4 .
.5 .30-12

:30-12 5
.6 31-12
.

:31-12 6

.7 .32-12

774

:32-12 7
.8 .33-12

:33-12 8
.9 34-12
.

:34-12 9

775

.10 12.35 .

:35-12 10


.1 .
.2 .
.3 .
.4 .
.5

: ) G = (V,E n n ... 1 0
1 s .W
:

.k

776

prim2 .msTreeType
.
.6 .
0

.7 G )= V(G
) V(G

k j 1 j n 1 k n

>

.n

j < k . G .
.
)
( .

.
] topologicalOrder [n 1 ] topologicalOrder [n 2.
C++
topologicalOrderT .graphType
.

777


13

:
.
.

.
.
4 .
.
. 4 vectordeque
5 .list ) stack (
7 ) queue ( ) priority_queue (
.8 4
.
pair
.

778

:pair
pair .
.pair
. map multimap
pair .
pair .utility pair
:
pair : .
pair:

expr1 Type1 expr2 .Type2


pair first second
. first second pair
pair .
1-13 .pair
:1-13
:

1 x pair x int
.double x pair
first second
.

779

2 y .pair y int
.double y first 13
second .45.9
3 z pair z .int
z first 10 second .20
4 ) name( pair
.string name first " "Bill
second "."Brown
5 employee .pair employee
string .double employee
first " "John Smith second .45678.50
:
;x first = 50
50 first x :
;"name.second = "Calvert
" "Calvert second .
.pair
1 .5

;cout<<y.first<<" "<<y.second<<end1

45.9 13 :

" "<<cout<<name.first

: ""Bill Brown

;<<name.second<<end1
" "<<cout<<employee.first

: 45678.50

;<<employee.second<<end1

John Smith 45678.50

:pair
pair pair

:
x y pair x y ) .
x y
x (.y 1-13 .pair

780

:1-13 pair

x==y

) (x.first == y.first )(x.second == y.second

x<y

) (x.first < y.first ) (x.second >= y.second )(x.second < y.second

x <= y

) (x < y )(x == y

x>y

)(x <= y

x >= y

)( x < y

x != y

)( x == y

pair :make_pair
utility .make_pair make_pair
pair . make_pair :

make_pair make_pair
.pair make_pair
.make_pair
:
)'make_pair (75, 'A
.pair 75 .A
make_pair .
2-13 .make_pair

781

:2-13

782

:
50 87.67 :3
:4
0 0 :6
*** :8
75 80 :In funcExp :17
87 H :In funcExp :18
198 K :In funcExp :18
250 Hello :In funcExp :19
Hello There :In funcExp :19
Hello World :In funcExp :20
22 Sunny :In funcExp :20

65
35

:
.
< ) ( .
.

.
. .
) ( .

.
:
sets
multisetes
maps
multimaps

783

.
set : :multiset
setmultiset
. < ) ( .
. .
.
set multiset multiset
.multiset
set set multiset
.multiset set multiset
.set
:
>#include <set
set:multiset
set multiset .
.
2-13 set / multiset ) . 2-13
ctType set (.multiset
:2-13 set / multiset

;ctType<elmType> ct
;ctType<elmType, sortOp> ct
;)ctType<elmType> ct (otherCt

;)ctType<elmType, sortOp> ct (otherCt

set multiset ct >


set multiset ct
sortOp
set multiset .ct otherCt
ct > . ct otherCt
.
set multiset .ct otherCt
ct .sortOp ct
otherCt . ct
otherCt .

:2-13 set / multiset

784

;)ctType<elmType> ct (beg, end

;)ctType<elmType, sortOp> ct (beg, end

set multiset ct
beg end-1 .ct begend
.
set multiset ct
beg end-1 .ct begend
.sortOp


. :

1 intset set int


. 2 otherIntset set
int )
otherIntset ( . 3 4 . 24
.
2 4 <
> greater<int < . << .C++
greater 2 4 " "
.
set :multiset
ct set .multiset 3-13
. 3-13
. . ct
set .multiset

:3-13 set multiset

785

;)ct.insert (elem
;)ct.insert (position, elem

;)ct.insert (beg, end


;)ct.erase (elem
;)ct.erase (position
;)ct.insert (beg, end
;) ( ct.clear
;)ct.find (elem

ct
.
ct .
position .
position .
ct beg end-1
beg end .
elem .
position
.
beg end -1 beg
end .
.ct ct.
ct .elem
) ( .ct.end

3-13 set :multiset


:3-13

786

787

:
20 16 8 3 :intset :9
30 36 39 59 84 456 238 :intsetA :19
:23 59 30 36 39 84 156 238 :intsetA
:31 :
30 36 84 156 238 :Intset
30 36 84 156 238 :intsetB :35
:39
:intsetB
:namesMultiSet :51
1 intset .set 2 intsetA
set . 3 intGtIt .set
intGtIt set int .
4 screen ostream
.int
5 8 16 8 20 3 intSet
10 .intSet 9
9 11 .

788

12 18 36 84 30 39 59238 156
intSetA 20 .intSetA
19 19 21
. intSetA .
22 59 .intSetA 26 intGtIt
.intSetA 27 28 29 intGtIt
.intSetA 29 intGtIt
.intSetA
30 intSetA .intGtIt
34 41.
42 namesMultiSet .multiset
. 43 iter
namesMultiSet string
.multiset
45 50 Donny Zippy GoofyHungry
Goofy Donny .namesMultiSet 52
.namesMultiSet
map ::multimap
map multimap / .
. >
) ( .
.
.
map multimap multimap
.map
map map
multimap .multimap map multimap
.map
:
>#include <map
map :multimap

789

map multimap .
.
4-13 map / multimap ) .
4-13 ctType map (.multimap
:4-13 map / multimap

map multimap ct
;ctType<key, elmType> ct
>.
; ctType<key, elmType, sortOp> ct map multimap ct
.sortOp

:4-13 map / multimap

;)ctType<key, elmType> ct (otherCt

map multimap .ct


otherCt ct > .
ct otherCt .
map multimap .ct
otherCt ct
.sortOp ct otherCt
. ct otherCt
.
map multimap ct
beg end-1
.ct beg end .
map multimap ct
beg end-1
.ct beg end
.sortOp

ctType<key, elmType, sortOp> ct


;)(otherCt

;)ctType<elmType> ct (beg, end

ctType<elmType, sortOp> ct (beg,


;)end


. :

790

1 intmap map int


. 2 otherIntMap map
int )
otherIntMap ( . 3 4
. 2 4 .
2 4 <
> greater<int < . << .C++
greater 2 4 " "
.
map :multimap
ct map .multimap 5-13
map .multimap
5-13 . .
ct map .multimap
:5-13 map multimap

ct map
;)ct.insert (elem
.
;) ct.insert (position, elem ct .
position .
position .
ct beg end-1
;)ct.insert (beg, end
beg end .
elem .
;)ct.erase (elem
position
;)ct.erase (position
.
beg end -1 beg
;)ct.insert (beg, end
end .
.ct ct.
;) ( ct.clear
ct .key
;)ct.find (key
) ( .ct.end

4-13 map :multimap

791

:4-13

792

:
:13 :intMap
16
1
8
2
3
3
20
4
43
6
28
8
16
12
60 15
18
20
:22 :intMap
16
1
8
2
20
4
43
6
28
8
60 15
18 20
:namesMultiMap :34
Donny
A1
Dumpy
A1
Hungry
A2
Zippy
B1
Goofy
D1
Goofy
K1
1 intMap map 2 mapItr
.map mapItr map
.int

793

3 12 .
16 .1 3 11 make_pair
12 pair .
for 14 .intMap
17 12 intMap 18
mapItr .intMap 19 20
mapItr .intMap 20 mapItr
.intMap 21 intMap .mapItr
for 23 .intMap
26 namesMultiMap .multimap
namesMultiMap ) string ( . 27
nameItr .multimap
28 33 .namesMultiMap for
35 .namesMultiMap
:
4 5 .
. 6-13
.
:6-13 .

vector

><vector

deque

><deque

list

><list

set

><set

multiset

><set

map

><map

multimap

><map

794

)( stack

><stack

)( queue

><queue

) (priority_queue

><queue

:
.
) ( .
.
.
.
.algorithm
.
.
:
4 5
.
.
.
.

.
.
.
copy
.
:
.
.
.

795

.
.
algorithm
.numeric
:
.
. 7-13
: :7-13
max_element
min
min_element
mismatch
search
search_n
upper_bound

find_end
find_first_of
find_if
for_each
includes
lLower_bound
max

adjacent_find
binary_search
count
count_if
equal
equal_range
find
:


. 8 -13 .
: : 8-13
rotate_copy
set_difference
set_intersection
set_symmetric_difference
set_union
sort
stable_partition
stable_sort
swap
swap_ranges
transform
unique
Unique_copy

prev_permutation
random-shuffle
remove
remove_copy
remove_copy_if
remove_if
replace
replace_copy
replace_copy_if
replace_if
reverse
reverse_copy
rotate

796

copy
copy_backward
fill
fill_n
generate
generate_n
inplace_merge
iter_swap
merge
next_permutation
nth_element
partial_sort
partial_sort_copy
partition

random_shuffle

next_permutation partitionprev_permutation

reverse

reverse_copy

rotate

rotate_copy

stable_partition .
:
. 9-13
.
:9-13 :
accumulate

inner_product

adjacent_difference

partial_sum

:
10 .
.
.
) i ( 2i ) 2i + 1 ( .

. 10-13
.
:10-13 :
make_heap

push_heap

pop_heap

sort_heap

.
.
.C++
.
.

. .
.

797

:

.
.
adjacent_find
. ) (
.
.
) ( . ) (.

.11-13
.functional
:11-13 :


********
>plus <Type
********
>minus<Type
>******** multiplies<Type
*********
>divides<Type
*******
>modulus<Type
*******
>negate<Type
5-13 .

798

:5-13

799

:
90 = num :3
Hello There = str :8
:9 3460 = 26
8 7 6 5 4 3 2 1 :intList :13
:17 36 = intList
:19 40320 = intList
12-13 :
:12-13

>equal_to<Type

>not_equal_to<Type

>greater<Type

true .false
;equal_to<int>compare
;)bool isEqual = compare (5, 5
isEqual .true
true .false
;not_equal_to<int>compare
)bool isNotEqual = compare (5, 6
isNotEqual .True
true
.false
;great<int>compare
;)bool isGreater = compare (8, 5
isGreater .true

800

:12-13

>Greater_equal<Type

>less<Type

>less_equal<Type

true
.false
;greater_equal<int>compare
;)bool isGreaterEqual = compare (8, 5
isGreaterEqual .true
true
.false
;less<int>compare
;)bool isless = compare (3, 5
isless .true
true
.false
;less_equal<int>compare
;)bool isless = compare (8, 15
isless .true


. adjacent_find
.
. :vecList
}vecList = {2, 3, 4, 5, 1, 7, 8, 9
vecList .
adjacent_find :

intItr .vector adjacebt_find ( vecList.begin


) vecList
. 5 .intItr
6-13 .
:6-13

801

802

:
1 = isEqual :3
"Hello" :10 "."There
9 8 7 1 5 4 3 2 :vecList :15
:20 vecList 1 5 :
:21 vecList
4 :
13-13 .
13-13


>logical_not<Type
>logical_and<Type
>logical_or<Type

true false .false


.
true ytue
.false .
true true
.fakse .

:
.
.
- . .
.
.
:
:

1 list 5 2
vList .vector vList
.vList list .vList:
vList copy
.
for
push_back vecList .

803

.
:
back_inserter front_inserter.inserter
:back_inserter push_back
. .
vList back_inserter :
:front_inserter push_front
. . vector
push_front .vector
:inserter insert .
:
.
7-13 :
:7-13

804

:
8 7 6 5 4 3 2 1 :vecList1 :6
8 7 6 5 4 3 2 1 :vecList2 :10
1 2 3 4 5 6 7 8 :tempList :15
:
.
.
.

.vector
outputItr inputItr forwardItr
.
fill:fill_n
fill fill_n n .
.

805

algorithm :

fill
. fill_n

. 8-13 .
:8-13

:
:4 vecList 22 2 2 2 2 2 2 2 :
:8 5:
2 2 2 2 2 5 5 5
1 2 vecList 8 screen ostream
cout . 3 fill vecList

806

2 vecList .2 ) ( vecList.begin
vecList ) ( vecList.end
.vecList 5 vecList copy
7 fill_n 5 .vecList fill_n
) ( vecList.begin . fill_n 3
. 5 . 5
.vecList 9 .vecList
generate :generate_n
generate generate_n .
algorithm :

generate firstlast 1 ) ( .gen


generate_n first first+n 1 first
) ( .gen gen . gen
. 9-13
.
:9-13

807

:
vecList :4 8 7 6 5 4 3 2 1 :
vecList :8
8 7 6 5 4 11 10 9 :
nextNum n
.1 n .n
nextNum 1 2.
1 2 vecList 8 screen ostream
cout . 3 generate
vecList .nextNum 3
n nextNum .9
.vecList

808

7 generate_n vecList
nextNum . ) ( vecList.begin
vecList 3
) generate_n .(7 9 .vecList
find find_if find_end :find_first_of
find find_if find_end find_first_of
. .algorithm find find_if
:

find firstlast -1 .searchValue


searchValue
.last find_if firstlast -1
) op ( .true )op (rangeElement

.last
10-13 find:find_if
:10-13
:

2 charList vector :

809

charList ''d
.position ' 'd charList .3 position
3 .charList
:
find_if .charList
isupper cctype .find_if
charList . position
.charList
find) find_if 1
(.
find_end .find_first_of
find_end:

find_end first1last-1
.first2last2-1 first2last1-1
.last1 find_end
first1last1-1 first2last2-1
.first1last1-1
) (elementFirstRange, elementSecondRange.
find_first_of:

810

first2last2-1 first1last1-1
.first1last1-1
first2last2-1 first1last1-1
) op (elemRange1, elemRange2 .
.last1-1
11-13 find_end.find_first_of
:11-13
:

find_end list2 .list1


list2 list1 ) 6 ( .
location 6 list1 .list1
:

find_first_of list1
list3 .list1 list3 list1 34
list1 1 .list1 location
1 list1 .list1
find_end) find_first_of
2 (.

811

remove remove_if remove_copy:remove_copy_if


remove remove_if
. remove_copy
.
remove_copy_if
. .algorithm
remove remove_if:

remove .firstlast-1
. remove_if
firstlast-1 ) op (element .
.
.
) (9 7 5 2 7 3 .7 7
.(79 5 2 3) : ) 9 .(5
12-13 ) . 810
12.(14
remove_copy.remove_copy_if

812

remove_copy first1last1-1
value .destFirst
remove_copy_if first1last1-1
) op(element .destFirst
.
12-13 removeremove_if
remove_copy.remove_copy_if
:12-13

813

814

:
:6 A F e D c A B A a A :
:9 F e D c B a :A
:13 e c a :
25 12 55 34 78 34 21 56 34 12 :intList :20
temp1 :25 intList 34:
25 12 55 78 21 56 12
temp2 :30 intList
0 0 0 0 0 0 0 55 78 56 :50
2 vector charList char charList
cList .1 3 vector
lastElem .newLastElem 4 ostream .screen
6 charList 8 remove
' 'A .charList

815

.lastElem 10
.
) 10 charList.begin ( ) lastElem-
(.1 12 remove_if charList
remove_if .newLastElem 14
.
17 vector intList int intList
list .16 21
.intList 24 34 intList
.temp1 intList . 26 temp1
28 vector temp2 int 10
temp2 . 29 remove_copy_if
intList .50 31
.temp2
replace replace_if replace_copy:replace_copy_if
replace
replace_if
. :

replace firstlast-1
) oldValue ( ) newValue ( .
replace_if firstlast-1 ) op(element
) newValue (.

816

replace_copy replace .copy


replace_copy_if replace_if .copy
replace_copy:replace_copy_if

replace_copy firstlast-1
.destFirst
. replace_copy_if firstlast-1
.destFirst ) op (elelemnt
. ) (
.
13-13 replace replace_ifreplace_copy
.replace_copy_if
:13-13
:

2 charList :

817

replace ' 'A ' 'Z .charList


charList:

replace_if '*' .charList


charList:

9 vector intList int intList


list .8 9 :intList
10 temp int :

intList temp 34 .
intList temp:
:

818

lessThanEqualTo50 true ) num ( 50


.false :

replace_copy_if intList temp


50 .50 replace_copy_if
.lessThanEqualTo50 13 temp :
replacereplace_if
replace_copy) replace_copy_if 3 (.

swap iter_swap:swap_ranges
swap iter_swap swap_ranges .
.algorithm :

swap iter_swap
first .second swap_ranges
first1last1-1 .first2
.
14-13 .

819

:14-13

820

:
:5 K J I H G F E D C B A :
:9 :
K J I H G F D C A B
:13 :

821

K J I H G F C D A B
:18 :
K J I H F G C D A B
10 9 8 7 6 5 4 3 2 1 :intList :24
intList :28
10 4 3 2 1 5 9 8 7 6 :intList
:32 intList :
10 4 3 2 1 5 9 8 7 6 :33
10 9 8 7 6 5 4 3 2 1 :intList :36
2 vector charList cList
.1 6 charList 8
.charList 12
iter_swap ) .charList
charList .(0 16 charItr
.charList 17 charItr
.charList 19 ) .charList
18

18 20 (.

22 vector intList
.21 25 .intList 27
swap_ranges intList intList
.intList 29 ) .intList
28 28 30
(.
31 list .intList
34 list 37 .intList

search search_n sort:binary_search


search search_n sort binary_search .
.algorithm
search:

822

search first1las1 -1 first2last2 -1

first1last1 -1 first2last2 -1
.first1last1 -1

.
op

) (elemFirstRange, elemSecindRange .
first1last1 -1
.false
search_n:

search_n firstlast -1
. firstlast -1
count .value
firstlast -1
count ) op (elemRange, value .
.last
sort:

823

sort firstlast-1
.op
binary_search:

true ) searchValue (
firstlast-1 .false op
.
15.-13 .
:15-13

824

:
49 5 62 56 34 25 12 43 38 78 34 34 56 34 12 :vecList :6
56 34 :list :9
:14 list .vecList first vecList :
1
:19 34 vecList 3 :
vecList :23 :
78 62 56 56 49 43 38 34 34 34 25 12 12 5
:29 43 .vecList
2 vector vecList intList
.1 3 list
.
7 vecList 12 search
vecList ) ( vecList list

825

. 13 16
14 .
17 search_n vecList
.34 18 21 .
22 sort vecList 24 .vecList
23 23
25 .
27 binary_search .vecList 28
31 .
adjacent_find merge:inplace_merge
adjacent_find
. :

adjacent_find
.
firstlast-1 ) op (elem, nextElem elem
firstlast-1 nextElem .elem
.last
intList .int intList:
:

2 listItr .int
3 adjacent_find ) (
.
.listItr 3 listItr .intList

826

vecList vector .int vecList:


:

intItr vector vector .int


6 adjacent_find
vecList .vecList adjacent_find
) greater ( vecList
. .intItr 6
intItr .9
) merge ( . merge
. .
. merge:

merge first1last1 -1
.first2last2 -1 destFirst .
> .
op ) op (elemRange1, elemRange2 .true
.
.
:

827

7 8 list1 .list2 9
intList .int 10 merge list1.list2
merge 10 ) back_inserter (
.intList 10 intList
:
inplace_merge .
:

firstmiddle-1 .middlelast-1
.first


op

) op(elemSeq1, elemSeq2 .
:

vecList .vector vecItr vector


.2 :
vecList :

828

adjacent_findmerge
) inplace_merge 4 (.
reverse reverse_copy rotate:rotate_copy
reverse .
reverse:

.firstlast-1 3 5 2 1) = vecList
(4 .(1 2 5 3 4) = vecList
reverse_copy
. reverse_copy:

firstlast -1
.destFirst .
rotate :

firstnewFirst-1 .
newFirst . :

vecItr . :
vecList :

829

rotate_copy rotate .copy


.
:

firstlast-1 destFirst
middle firstlast-1
.
.
reverse reverse_copy rotate rotate_copy
.algorithm 16-13 .
:16-13

830

:
8 6 4 2 0 9 7 5 3 1 :intList :6
intList :10 1 3 5 7 9 0 2 4 6 8 :
:14 8 6 4 2 0 9 7 5 3 1 :
intList :20 1 3 5 7 9 0 2 4 6 8 :
intList :24 6 8 1 3 5 7 9 0 2 4 :

831

intList :29 6 8 1 3 5 7 9 0 2 4 :
:32 2 4 6 8 1 3 5 7 9 0 :
:37 8 1 3 5 7 9 0 2 4 6 :
.

count count_if max max_element minmin_element

:random_shuffle
count .
:

count value
.firstlast-1
count_if .
:

count_if firstlast-1 )op (elemRange


.
max .
:

.Type
.comp
max_element .
:

832

.firstlast-1
.comp
.firstlast-1
min .
:

.Type
.comp
min_element .
:

firstlast-
.1 .comp
.firstlast-1
random_shuffle .
:

833

firstlast-1
. firstlast-1
.rand
17-13 :
:17-13

834

:
Z F e D c Z B Z a Z :charList :4
:8 ' 'Z 4 :charList
:10 7 :charList
:1325 12 55 34 78 34 21 56 34 12 :
:17 78 :
:19 12 :
:21 34 34 21 55 78 12 56 25 34 12 :
.
for_each:transform
for_each
. :

835

func .firstlast-1
func .for_ech
transform . :

transform .
destFirst op
.first1last-1
.
transform .
bOp ) bOp (elemRange, elemRange2
first1last1 -1 .destFirst
.destFirst
.
18 -13 .
:18 -13

836

:
e d c b a :charList :4
charList :8
E D C B A :
:133 11 7 1 5 8 2 :
:16 6 22 14 2 10 16 4 :for_each
837

:19 6 22 14 2 10 16 4 :for_each
7 transform charList
. 8
8 10 . transform

) (7

toupper .ccType
17 for_each
.doubleNum doubleNum num .int
num .num num
. 16
cout doubleNum ) for_each .(17
20 . 19
19 20 .

includes set_intersection set_unionset_difference

:set_symmetric_difference
) includes (
set_intersectionset_unionset_difference

.set_symmetric_difference

.
includes
. :

includes first1last1-1
first2last2-1 . true
first2last2-1 .first1last1-1
true first1last1-1 .first2last2-1

838

.
op .
19-13 :includes
:19-13

:
E D C B A :setA :5
L K J I F E D C B A :setB :8

839

U O I E A :setC :11
setA :15 setB
setC :21 setB
.
set_intersection .
:


first1last1-1 .first2last2-1
.destFirst
. .
.op
.
:

840

8 seta 8 AintersectC
8 .setC 4 DintersectE 4
setD.setE
set_union .
:


first1last1-1 .first2last2-1
.destFirst
. .
.op
.
setA setC setB setD setE .:

8 setC .AunionC 4
setD setE .DunionE
20-13 set_union.set_intersection
:20-13
//
// .

841

842

:
8 7 5 4 2 = setA :12
7 6 5 4 3 2 1 = setB :15
15 8 8 5 2 = setC :18
12 7 6 4 4 1 = setD :21
:25 8 7 6 5 4 3 2 1 :AunionB
:29 15 8 8 7 5 4 2 :AunionC
:33 12 7 6 5 4 4 3 2 1 :BunionD
:37 7 5 4 2 :AintersectB
:41 8 5 2 :AintersectC
.
set_difference
. :

843

first1last1-1
.first2last2-1
.destFirst
. .
.op
.
:

5 setD setE 5
.DdifferenceE set_symmetric_difference
:

844

first1last1-1
first2last2-1
first2last2-1 .first1last1-1
set_symmetric_difference
range1_difference_range2 .range2_difference_range1
.destFirst
.
. .op
.
set_symmetric_difference range1_union_range2
.range1_intersection_range2
:

(10 7 4 3) = Bdifference .(15 1) = Cdifference :

21-13 set_difference:set_symmetric_difference
:21-13
:

845

Adifference seta setC


:

BsymDiffC setB setC


setC setB:
set_difference
) set_symmetric_difference 5 (.
accumulate adjacent_difference inner_product:partial_sum

accumulate adjacent_difference inner_productpartial_sum

. .
. accumulate
.
.
accumulate .
.
.numeric

accumulate
init .firstlast-1 init
.

846

. init 1
.
adjacent_difference :


firstlast-1 .
:
adjacent_difference:
.
.
.
adjacent_difference op
. .destFirst
) (7 3 8 6 5 2 )30 10 2
.(12 24 48
. 22-13
accumulate.adjacent_difference

47

:22-13

848

:
8 7 6 5 4 3 2 1 :vecList :4
:7 36 = vecList
:9 40320 = vecList
1 1 1 1 1 1 1 1 :newList :11
56 42 30 20 12 6 2 1 :newList :14
.

849

inner_product .
:

first1last-1
first2 .init
elem1 elem2
.first2
:
elem2 + elem1 + init = init
. ) (8 7 4 2 )1
(9 6 4 init . :
132 = 9 * 8 + 6 * 7 + 4 * 4 + 1 * 2 + 0
op1
.op2 :
init op1 (elem1 op2 elem2) = init
partial_sum :


firstlast-1 .
firstlast-1
firstlast-1
firstlast-1 . :
)(6 4 3 1

850

partial_sum :
)(14 8 4 1
.op
:
)(6 4 3 1
partial_sum :
)(72 12 3 1
destFirst
.
23-13 inner_product.partial_sum
:23-13
:

3:4

vecList newVList
sum:

851

vecList newVList
* sum:

partial_sum .36 28 21 15 10 6 3 1
newVList:

partial_sum 5040 720 120 24 6 2 1


.40320 11 vecList
+ * . newVList:
inner_productpartial_sum
) 6 (.


.1 .
.2 :
.
.3 .
.4
.
.5 pair .
.pair map multimap pair .

852

.6 pair .utility
.7 make_pair pair.
.8 make_pair .utility
.9 .
> ) (.
.10 setsmultisets
maps.multimaps
.11 set .
.12 multiset .
.13 set .set
.14 multiset .multiset
.15 set multiset
.set
.16 insert erase clear .
.17 map multimap / .
.
.18 map multimap >
) ( . .
.
.19 map multimap multimap
map.
.20 map .map
.21 multimap .multimap
.22 map multimap
.map
.23 .algorithm
.24
.
.25 .
.26 /
.

853

.27
.
.28 .
.29 ) (.operator
.30 plus minus multipliesdivides
modulus.negate
.31 equal_to not_equal_togreater
greater_equal less.less_equal
.32 logical_not logical_and
.logical_or
.33 .
.34
.
.35 .
.36 .
.37 .
.38 back_inserterfro,nt_inserter
inserter .
.39 back_inserter push_back .
.40 front_inserter push_front .
.41 vector push_front
.vector
.42 inserter .
.43 fill fill_n n.
.44 generate generate_n .
.45 find find_if find_end find_first_of
.
.46 remove .
.47 remove_if .
.48 remove_copy
.

854

.49 remove_copy_if
.
.50 swap iter_swap swap_ranges .
.51 search search_n sort binary_search
.
.52 adjacent_find
.
.53 merge .
.54 inplace_merge .
.55 reverse .
.56 reverse_copy
. .
.57 rotate .
.58 rotate_copy .
.59 count .
.60 countt_if
.
.61 max .
.62 max_element .
.63 min .
.64 min_element .
.65 random_shuffle
.
.66 for_each
.
.67 transform
.
.68 includes .
.69 set_intersection
.
.70 set_union .

855

.71 set_difference
.
.72 set_symmetric_difference

.
.73

accumulate adjacent_diffeenceinner_product

partial_sum .

.1
.2 :
-

C++ ) (1, Hello .temp

- C++ temp
.
.3 :

.4 set .map
.5 . Map stateDataMap )
( .string
. C++ :stateDataMap
) () () () (
) ( ) (.
. C++ .stateDataMap
. C++ .
.6 setmultiset
.7

856

.8 charList vector:
:

lastElem vector vector .char


.9 intList vector:
:


.10 intList vector:

.11 intList vector:

.12 setA setB setD setC :

857

A B A C B D A B A C


.1 find.find_if
.2 find_end.find_first_of
.3 replace replace_ifreplace_copy
.replace_copy_if lessThanEqualTo50
.13-13
.4

adjacent_findmerge

.inplace_merge
.5

set_difference

.set_symmetric_difference
.6 inner_product.partial_sum
) .7 ( 8 4

.

.
/ .
.
/
.

858


/ . .indexByGain
/ indexByGain .
indexByGain
.
.8 14 5 set
.
.9 15 5 set
.
.10 15 5 set

.

859


()

and
bitand
case
compl
default
dynamic_case
export
for
inline
namespace
operator
protected
return
static
template
try
union
void
xor

and_eq
bitor
catch
const
delete
else
extern
friend
int
new
or
public
short
static_cast
this
typedef
unsigned
volatile
xor_eq

860

asm
bool
char
const_cast
do
enum
false
goto
long
not
or_eq
register
signed
struct
throw
typeid
using
wchar_t

auto
break
class
continue
double
explicit
float
if
mutable
not_eq
private
reinterpret_cast
sizeof
switch
true
typename
virtual
while


)(

) (

) :: (
) :: (
)(
>[] -
) -- ++ (postfix
typeid dynamic_cast
static_cast const_cast
reinterpret_cast
) -- ++ ) + ! (prefix( )(
* ) (
~ & )(
new delete sizeof
*->* .
* % /
+
>> <<
< <=
> >=
== !
&
^
|
&&
||
:
= =% =/ =* =- =+
>>= <<= &= |= ^=
throw
) , (

861


)(



3
2
1
0
etx
stx soh nul
0
cr
ff
vt
1f
1
etb syn nak dc4
2
!
b
us
rs
3
+
*
)
(
4
5
4
3
2
5
?
>
=
<
6
I
H
G
F
7
S
R
Q
P
8
]
/
[
z
9
g
f
e
d
10
q
p
o
n
11
}
z
y
x
12

4
eot
so
can
"
,
6
@
J
T
^
h
r
|

5
enq
si
em
#
7
A
K
U
_
i
s
{

6
ack
dle
sub
$
.
8
B
L
V
'
j
t
-

7
be1
dc1
esc
***
/
9
C
M
W
a
k
u
del

8
bs
dc2
fs
&
0
:
D
N
X
b
l
v

9
ht
dc3
gs
'
1
;
E
O
Y
c
m
w

12-. 9-0
.
) 6 ( ) 5
( .A ) 65 (66 .A
b 32 .
32 00 31 127
.
:

862

nul

vt

syn

soh

ff

etb

stx

cr

can

etx

so

em

eot

si

sub

enq

dle

esc

ack

dc1

Bel

)(

dc2

bs

1
2

fs

gs

dc3

rs

ht

dc4

us

lf

nak

del



4
3
2
1
0
b
6
7
.
&
8
;
)
*
$
!
9
10
?
>
11
@
#
:
12
f
e
d
c
b
13
14
r
q
p
o
15
u
t
s
16
17
[
]
18
B
A
19
I
H
20
O
N
M
L
K
21
22
Z
Y
X
W
23
4
3
2
1
0
24

<

/
,

'
g
j

=
h
k

"
i
l

x
\

y
}

z
{

G
J

Q
S

R
T

863

_
a

24 -6 9-0
.
) 19 ( 3
) ( .A ) 193 (194
.A b 32 .
.
63 . 255-250 .

)(

.

+

&

&&

||

==

<

=<

>

=>

=!

=+

=-

=*

=/

=%

=^

=|

=&

<<

>>

=>>

=<<

++

--

*>-

>-

][

)(

new

delete

.

.

*.

?:

::

864

sizeof


)(

C++
. .

.
:cassert



int ) (
) assert(

) ( .


.
#define NDEBUG > #include <cassert
.assert
:cctype

)isalnum (ch


ch char

)iscntrl (ch

ch char


int : ch
)' 'Z' 'A ' 'z' 'a ' '0

' ('9 ) (
)(.
int : ch
)
0-31 (127
) (
)((.

865

) ch isdigit (ch char


int : ch " "0 " "9
)( )(.

) ch isgraph (ch char

int : ch
) " "1 (0-0
)( )(.

) ch islower (ch char

int : ch )' 'a '('z


)( )(.

) ch isprint (ch char

int : ch
) " "
(0~0 ) (
)(.

) ch ispunct (ch char

int : ch
)( )(.

) ch isspace (ch char

int : ch )
(
)( )(.

) ch isupper (ch char

int : ch )' 'A '('Z


)( )(.

) ch isxdigit (ch char int : ch


)" "9" "0 " "Z" -"A " "a " "z
)( )(.
) ch tolower (ch char

int : ch int
ch int
.ch

866


)toupper (ch


ch char


int : ch
int
ch int .ch

:cmath


x
)acos (x
1.0 x 1.0 x
)asin (x
1.0 x 1.0 x
)atan (x
x
)ceil (x
x
)cos (x

x
)cosh (x
x
)exp (x
x
)fabs (x
x
)floor (x
x
)log (x
0.0 < x
x
)log10 (x
0.0 < x


x 0.0
x 2/ 2/
x 2/ 2/
) x (x
.
90 = x x
hyperbolic x
e (2.718 = e) x
x
) x (x
) (ex
) (10x

867


)pow (x, y

)sin (x

)sinh (x
)sqrt (x
)tan (x

)tanh (x



x y . =x x y
0.0 y
0.0 x y
x .
90 = x

x 1
hyperbolic
x
x
x
x 0.0 x
x .
45 = x x

1
hyperbolic x
x

:cstddef
:
: NULL null ) (.
:cstring



char destStr
destStr strcat (destStr, srcStr
destStr srcStr ""0/
)srcStr
destStr

str1 strcmp (str1, str2 char :
> int str2 > str1

)str2
int str2 = str1
< int str2 < str1

868


strcpy (destStr,
)srcStr
)strlen (str



char destStr
destStr srcStr
srcStr destStr

int str
str char
) "("0/

:string
cstring

.string string

string : :

size_type .string : : npos :


string : : size_type .
string : : npose .string : : size_type
string str . str1 str2
)( string . string
1.

) ( str.c_str
getline
)(istreamVar, str

) ( str.empty

) C-string char

( .str
istreamVar istreamVar str
) istream ) .
.(str
str .(ifstream

)( string
this .void
true str

string .false

869


) ( str.length
) ( str.size
)str.find (strExp

(pos,

str.substr
)len

;)str1.swap (str2

;) ( str.clear
;) ( str.erase
;)str.erase (m
;)str.erase (m, n

;)str.insert (m, c

string::size_type


string::size_type


find str
str string
.strExp
strExp string
str .
.
strExp .string::npos
.
string str
pos len.pos .pos .len
) (str len " "
.str
len )
( . pos
) ( str.length
str1.str2

string.str1 str2
.string
.str

.str

str .m

string::size_type
m n .str
.int
< n str
.m
c m .str
m
string::size_type
c .

870


str.insert (m, n,
;)c
(m,

sr1.insert
;)str2

(m,

sr1.replace
;)n, str2


n c M
.str

m n
string::size_type
c .
str2 m .str
m n
string::size_type
str2 .
m n str1
m n
string::size_type .str2 < n str1
.str1
str2 .

)(
C++
:
2 .
.
.
. C++
.
.
:

871

baseClass derivedClass
baseClass .
.print :

callPrint p .baseClass callPrint


baseClass derivedClass .
callPrint .print :main

872

:
5 = x
*** : 3 = x
15 = a
*** *** callPrint
5 = x
3 = x
1 5 . 6 .7
6 callPrint one
7 callPrint
two .
6 7 x ) .
two 7 callPrint
7 (.
print baseClass ) 6 .(7
print callPrint .
p callPrint

baseClass ;) ( p.print

print .baseClass
) .
(.
7 .derivedClass
two print two .
C++
C++ .
.
.

. .
C++ .virtual
:

873

virtual .
print .
.
:
5 = x
*** : 3 = x
15 = a
*** *** callPrint
5 = x
*** : 3 = x
15 = a
7 print
) (.

. ) .
baseClass baseClass.h derivedClass
.(derivedClass.h :

874

:
5 = x
*** : 3 = x
15 = a
*** *** callPrint
5 = x
*** : 3 = x
15 = a

.
.
.
class
.

875

baseClass .derivedClass
:

:
two x .a x .
:

two p p
. p baseClass .
x two x .p :
;) ( p.print
print .baseClass
) . baseClass
baseClass.h derivedClass
.(derivedClass.h

876

:
5 = x
*** : 3 = x
15 = a
*** *** callPrint
5 = x
3 = x
6) 7 ( . 7
two p p .
p baseClass .
x two x .p
;) ( p.print callPrint print baseClass
.derivedClass ) x .(two
.
:
.
.
.

.
.
.
.
.
.
)
(.
.

877

:
3 & .
. :
;int x
;int &y = x
x int y .x
x y . y .:
;y = 25
) y ( x .25 :
;x = 2 * x + 30
) x ( .y
.
.
.
:

878

addressOfX int :
;return x
.x
testAddress
. .

879

:
x 50 = testAddress
25 = y x 25 = testAddress
:
;) ( int &y = a.addressOfx
y x .a :
;y = 25
.x
.
.
.
.
const .

. testAddress :

addressOfX :

880


)(
C++
C++
/ .

.C++
.C++ C++
C++ .
C++ : C++
)) (7 (.
:
C++ .

3 . .
C++ .
C++ . char
bool short int long .unsigned int 1-
.
:1-

int

2147483648 2147483647

bool

truefalse

char

128 127

. .
.

881

int C++ int


.
char C++ 256 char
65536 .
char .
C++
128 )( .
bool true : .false true false
. true false .
C++ . C++
float : double .long double
float double long double
. float double C++ .
:
- / * - + - .
C++ .
++ -- = +

= - * =

= / = % C++ .
C++ :
static_cast <dataType> expression
C:
dataType expression
:
C++ .const
:

conversion double
2.54.

882

cast double conversion = 2.54


C++
.

amountDue double
counter .int
;double amountDue
;counter

int

expression .
.
amountDue double quantity .int
quantity 20 150.00 :amountDue
;amountDue = quantity * 7.50
:C++ :
C++
C++ .
.
/ .iostream
power absolute sine .cmath
/
.
.
.

883


C++ . #
.C++ C++
.include
C++:

iostream :C++
># include <iostream

) . C++
(.
.C++
.
.C++
:C++
C++ : .
C++ .
. .C++
.cpp
) .(.obj

) .(.exe
.
firstProg.cpp firstProg.obj
.firstProg.exe
.cpp .obj .exe .
.

884

C++ .main
C++ .main main .
:
)typeOfFunction main (argument list
:
) ( int main
main int .
) } {( :
.
.
. C++
.
.
.
.C++

.
:
. /
C++ / C++.
:
cin
>> . cin >> :

885

) ( . .cin C++

>>

.
) (cin . miles .double:
;cin>>miles

double
.miles
cin . feet
inch .int :
;cin>>feet>>inch
feet inch
.
>>
. >> .
>> >>
.
.
>> .
payRate hoursWorked .double
:
;cin>>payRate>>hoursWorked

:
48.30 15.50
:
15.50

48.30

886

:
15.50
48.30
15.50 payRate 48.3 .hoursWorked

.
.2 >> 2 2
>> .
char 2 2
.2 int
double 2 .2
25:
;cin>>a

a . a char 2
.a a int 25 a double
25 .25.0 2-
.
:2-


char

int

) + (-

double

) + .(-

char >>
. int
double >>

887

) (
.
:
.
.
:
;wages = payRate * hoursWorked
+ *
+ .

int .
int double .
:
;int a, b, c
;double x
:
w 54
:
;cin>>a>>b
" "w a .int
:
78 48 67.93 35
:
;cin>>a>>x>>b
35 a 67.93 x 48 .b
) (:
;cin>>a>>b>>c
35 a 67 b ) . ( .
c int . c .
.

888


/ .
.
:
C++ cout << .
cout << :
. .cout C++

<<

.
cout :
.1 ) .
(.
.2 . ) end1
(el .
1- .cout cout
.
:1-
. .

1
2
3
4
5
6
7
8
9

;cout<<29 / 4<< end1


;cout<< "Hello there. "<<end1
;cout<<12<<end1
;cout<< "4 + 7" <<end1
;cout<< 4 + 7 <<end1
;cout<< 'A' <<end1
;cout<< "4 + 7 = "<<4 + 7<<end1
;cout<<2 + 3 * 5<<end1
;cout<< "Hello \nthere. "<<end1

7
Hello there.
12
7+4
11
A
11 = 7 + 4
17
Hello
there.

:Setprecision
setprecision .
.

.

889

.
setprecision .2
setprecision:

n .
setprecision cout . :
;)cout<<setprecision (2
.
.setprecision
setprecision .iomanip
include:
>#include <iomanip
:Fixed
.
.fixed
:
;cout<<fixed

.fixed fixed
.unsetf fixed
:
;)cout . unsetf (ios : : fixed
fixed .
scientific .
:Showpoint
.

.

890

.showpoint
.
;cout<<showpoint

:
;cout<<fixed<<showpoint
:setw
setw .
) setw (n n .
8
.

. x int x
:
;cout<<setw (5) <<x<<emd1
setw .iomanip
:
>#include <iomanip
setw setprecision

left:right
setw
.
. .left
left:
ostreamVar .
:
;cout<<left

891

left .unsetf
left:
ostreamVar . left
. left
:
;)cout . unsetf (ios : : left
right:
ostreamVar .
:
;cout<<right
:flush
end1 /n
. .end1

. .
end1
. end1
.

.
C++ flush .
end1 flush .
flush:
ostreamVar .cout
:
;cout<<flush
num :int

892

1 : .
. 1 .

. end1 .1
.
.
1 :
" "
.
: .
/ :
) (
) ( .
) ( . C++
.
/ .
:
: .
/ iostream
.
C++ fstream / .
fstream ifstream :
istream ofstream
.ostream
cin cout / .
>> cin

893

.cout / fstream
.
ifstream ofstream .
>> << / . C++ .
fstream /.
/ :
.1 fstream .
.2 .
.3 /.
.4 >> << / .
.5 .
.
.
fstream .
:
># include <fstream
. :
;ifstream inData
;ofstream outData
inData ifstream outData .ofstream
/
. open . :

fileStreamVariable sourceName
/.
2 .
prog.dat A
prog.out .A inData prog.dat

894

outData .prog.out prog.dat


prog.out .

\ a: \ . \a
\\ . C++
\\ a: .
C++ \\ a: .

. >> <<
/ . >> <<
cin .cout cin cout
. :
;inData >> payRate
prog.dat .payRate:
;outData <<"The paycheck is: $" <<pay<<end1
- $ 565.78 : .prog.out
.565.78
/ .
.
/ .
.
.close
2 3 :
;) ( inData.close
;) ( outData.close

895

/ :

/ .
.
.open open
.
.
.
:
C++ == != < =< > =>
C++ .
if ifelse switch whilefor
.dowhile .
C++ true
.false true 1 false .
C++ 1
.
896

boolean
true false .
C++ .
if:
)if (drivingCode = 5

C++ drivingCode = 5 5 5
.true C++
.drivingCode 5 true false
.boolean
C++ .
:
iostream
.
)
" "( . .
.
)_( .
)_(.
C++ .namespace
namespace:

namespace .
namespace .C++
C++ namespace .
:2-
:

897

globalType namespace : n
rate count .printResult
namespace .namespace namespace
namespace .
namespace:

rate :gobalType
;) ( globalType : : printResult
C++ : : . namespaceName
.namespace
namespaceName .
namespace C++ using
using :
) ( :namespace
)( namespace:
:
;using namespace globalType
namespace globalType :
; using globalType : : rate
rate .namespace globalType

898

C++ using .
using .namespace globalType
:

using namespaceName
namespace .Namespace namespace
namespaceName
namespace Namespace .
namespace namespaceName
namespace namespace .
3- 6- .namespace
:3-
C++:

ostream cincout
end1 std : : . ) (
) (iostream
.

899

:4-
C++:

pow .cmath
:5-
C++:

main iostream
std : : . using main
) ( std : : iostream
using.

900

:6-
C++:

C++:
t 2 main )
t (: : t main ) t .(5
) t (5 namespace expNspace main
expNspace : : ) t t (expNspace : : t
) t (2 t .main
) u (6 namespace expNspace main
expNspace : : ) u u (expNspace : : u
) u .(3

901

) x (4 namespace exp main


x expNspace : : x x main
.x
namespace printResult
namespace .

printResult

printResult ) expNspace : : printResult


.(printResult
iostream cmathiomanip
.namespace std
:
;using namespace std
:
C++ .void
:
:

) functionType (
.
.
: :
:
: :
:

: :

902

:
) (
.

.
.return
:void
void :

: :

:

. &

.
: :
:
: :
:


.
. ) .
(.

903

:7-

funexp .
: .
: .
: ) ( .
&
.
:8-
expfun :
one .int
two .int
three .char
four .double

. .
.
.

. .

.
.
.
.

.

904

. .
.

.
.C++
:
.
.
.return
void
.
:
. C++
.
.
:
.
.
.
.
.
.
.

funcExp . z u v w .
z u v w funcExp .

905

:
;int a, b
;char ch
;double d
:
.funcExp (a, b, d); .1
funcExp (a, 15, 34.6, 'B', 87, ch); .2
funcExp (b, a, 14.56, 'D'); .3
1 z u v .w 2 z
' 'B u 87 v
ch .w 3 z
' 'D u v.w
:
funcExp (a, 15, 34.6, 46.7); .1
funcExp (b, 25, 48.76, 'D', 4567, 78.34); .2
1 .z 2
w .v
:
.1
.2
.3
z 1
z 2
. 3 y y
.
:
C++
. C++

.
.C++

906

.
:
;)dataType arrayName (intExp
intExp . intExp
.
:9-
:
;]int num [5
num 5 .int ] num [0 num
] [1] num [2] num [3].num [4
:
C++ . ) (
:
indexExp .
. C++ .
:
;]int list [10
list 10 . ] list [0] list [1...

list

] .[9 :
;list [5] = 34
34 ] list [5 .list i
.int :
;list [3] = 63
:
;i = 3
;list [1] = 63
i 4 :
;list [2 * i 3] = 58

907

58 ] list [5 3 i * 2 .5
.
:
;list [3] = 10
;list [6] = 35
;]list [5] = list [3] + list [6
10 ] list [3 35 ] list [6
] list [3] list [6 ].list [5
:
C++ C++
.1

.
.
. .
:
C++ .
& .
.
. length
)( .
.C++
:

initialize int . initialize


.initialize

.

908

. const
. :

example x .y y
.
.

)(

.1 -
.1995
.2 C++
.1997
.3
.2001
.4 C++ . -
.1999
.5 3-1 -
.1973 1969 1973
.6 C++ . -
.1998
.7 :C++
.2002
.8 .
.1986
.9 C . -
1998 4-1 .2002 5

909


)(

:1
.1 . . . . . . . ..
.2
: x.
: x x
.
12 .4
.543 .
3 + n4 .
O(n) .
#define NDEBUG .7
.126 .
2 .
2 .
.13 (i) . .1
) (ii .3
) (iii .4
.

910

:2
.1 . . . . . . . . . .
. . . ..
.4
.
.
.5 .:
class bClass public aClass
:
class bClass : public aClass
. }.
.7
.

.11
7 = x :
11 = y + x 8 = y 3 = x :
.13 << .mystery
.14.

911

.16
friend strange operator+ (const strange&, const strange&); .
friend bool operator= = (const strange&, const strange&); .
friend strange operator++ (strange&, int); .
.18 2 friend bool . :
// Line 2

; )friend bool operator<= (mystery, mystery

.20 .
.23.
.24 .4
. type .
) .26 ( 12

)( Sunny Day

) .27 ( 21

)( OneHow

.28

:3
.1 . . . . . . . ..
.2 .
.
. p x .int x.p
.
..
. *p int q . q.*p
.5

78 78 .7

912

.8 5 p .q p q
. 7 q
p q . 8
.
40 32 25 19 14 10 7 5 4 4 .9
.12 7 p .q p q
. 8 p
q . 10
.
.13 25 17 11 7 5 :p
5 7 11 17 25 :q
.16
.
.18
. arrayListType intList .100 intList
.int
. arrayListType stringList .1000
stringList .string
. arrayListType salesList .100 salesList
.double
:4
.3
.5
.6 :
13 11 9 7 5
8 6 4 2 0 .7
9 7 3 .9
95 200 100 75 50 .11
210 35 5 23 0 34 76 70 .15

913

:5
.1 . . . . . .
.3 . . . . ..
.4 .
.
.
. ) B *list (struct
.
. ) B A->link->info (int
.
.
.
.6 .18
.7 . . ; s->info = B B s->info
.int
. . s = s->info s NULL
s->info.
28 20 42 30 .9
.10
.
25 45 15 2 38 18
intList = {3, 23, 43, 56, 11, 23, 25} .12
.14
50 35 23 45 0 34
138 23 45 38 0 34 76 46
:6
.1 . . . . ..
.4 .
.5
.

914

.6
.
.9 . .
. .
9 8 7 6 5 .
. .
.1015 .
6 .
.12 low high .
low.high

.14
:7
3 = x .1
9=y
7
13
4
7
45 = x .2
23 = x
5=x
5 14 34 10 :
.326 .
45 .
8 .
29 .
.4AB+CD+*E- .
ABC+D*-EF / + .
AB+CD- / E+F*G- .
ABCD+*+EF / G*-H+ .

915

Winter Spring Summer Fall Cold Warm Hot .6


50 40 30 20 10 .7
:8
0 = queueRear 50 = queueFront . .1
99 = queueRear 51 = queueFront .
76 = queueRear 25 = queueFront . .3
75 = queueRear 26 = queueFront .
51 .5
2 4 16 9 5 : .7
5 16 5 .9
. mystery .10
.13

916

:9
.1 . . . ..
.2 8 . 6 . 1 ..8 .
.3
.
first
0
0
3
4

1
2
3
4

last
10
4
4
4

mid
5
2
3
4

]list [mid
55
17
45
49


2
2
2
) 1 (

4 .7
.

1
2
3
4
5

first
0
6
9
10
11

last
10
10
10
10
10

]list [mid
mid
55
5
92
8
98
9
110
10


2
2
2
2

. .8
.4

.5 30 5.

917

.10 . 15 ] HT [15 101 ]HT[0


116 ] HT [16 ]HT [1
217 ].HT [17
101 .11
.16 0.85 1001 / 850 =
.17 0.5 1001 / 500 =
( 1/2 ) { 1 + (1 )) } = 1.5 .
(1 /2) = 1.25 .
10:
3 .1
15 58 32 71 30 28 25 21 18 12 10 .3
.655 65 58 100 54 95 64 80 48 28 40 16 32 38 36 .
.9 6 .
:
35 17 45 25 28 60 20 30 76 50 65 47 82 72 85
100
.10

918

94 14

:11
.1 . . . ..
.3
.4
.5
D C B E A F G .6
A B C D E F G .7
D C E B G F A .8
79 70 58 55 80 .9
.12

919

.15

2
.17 .

920

.18 .1-

4
:12
.2

5
5 3 2 4 1 0 .3
5 4 3 2 1 0 .4

921

.6

6
:

10

15

922

.7

7 -
9 3 8 4 5 6 2 0 7 1 .10
:13
. .2
.Duckey Donald .3
. .5
.

A B A K .8
.11

923


:
def .
tbl .
:
& )( .

901 897 896 153
&& ) ( : .tbl 849
>< ) (
77 41
)<<( " " )<( )>>(
" " )>(.
* )( . .
*= ) ( : 849 .
| )( : 849 .
| | )( : 849 .
} { )( : 878
] [ )( .
) :( : 17
) : : ( : 849 26 891
) ,( : 849 .
) .( . ) (
" ) ( : 77 41
= ) ( . postfix 446
== ) ( . .
! ) ( : 849 .
! = ) ( . .
< ) " "( . " "
< = ) " " ( . " ".
<< ) " "( . .

924

>) - ( : 849 145-144 .


> ) " "( . " "
> = ) " " ( . " ".
>> ) " "( . .
) ( 849 . . . 20
) - ( . .) # ( postfix .446 877
20
) ( ) ( . .
) % ( : )( 849 .
) + ( . .
849 .
20
) ++ ( . .
) = + ( : 849 .
) : ( : 849.
; ) ( 16 877
) / ( . .
) = / ( : 849.
)( ) ( : .880
)( : .35 _ ) ( : 890
:
: .860 147
394 392
395-395 391

925

A
859 .
37
37
646-644 698 AVL
655-654
114-112
.39-38
498-497 customerType
n .396-396
.508 queueType
.504-503 serverListType
501-499 serverType
729-701 341-339 videoType
.736-735 729-728
.549-547
.39-38 38-37
.526-524 185-182
.529
.114-112
.293-290
.321-319
.308
480-478
.485-484
752
439 430-429
.413-411
307-290
.37-36
37.

926

.
.901-900
.C++ )( C++
.145-144 24 22-21
.874-872 70 68
145-144 struct
) accumulate ( .837-836 835
)) acos (x ( 859.

896
.896 void
: .902 25
.
:
550
471 470 .482 472-471
.509 508 487
411 410-409 418-415
.436-433

)(+
.107 98-97
849.
)( 471 470
509 508 487
.482 472-471
)&( .139 138-137 135
872
849.
.874-872
) ( .143-135
.726 725-724
.723-723
) ( .726 723
) adjacent_difference ( .837-835
)adjacent_find ( .816-815 792
. 218
15-8
.399 398-391
.
. ) (
: 12-11
927

12
. ))O(g(n
373-372 369
.218
.
: 872
. .
. .
)&( .

897 896 153
)&&( : 849.
) ( .3
)&&(:
849.
)><(
77 41
)<<( " " )<( )>>(
" " )>(.
.652 644
859.
:
.207 151
.
.876
441 infix 442 postfix.
441 :
849.
.Postfix postfix


.839-835 788

928

.151
.
.876
.9699
.446 441 postfix
849.

.791-789
) (
.901-900
802-800
.816-815 792
/ ) : :(.
806-802
.808-806
)] [(
.177 173-172
849.
.900
.901-900
.565
.563-560
.901
585 563-561
.198-180
602-595
/ .185
.190-185
.190
.602-596
.191-190
.795-794
.526-524 185-182
.190
.194-193 188-186
.631 273
.191
.585-580
.585 584 583 582-580 pivot
.206-198
929

.194 190 189-188


189
189
.193-191
: 605-596
.572-566
586-579
.566-560
198-195
arrayListType
.526-524 185-182
.190-185
900902-900
. C .474-473
.902
. .
. .
. .
. .
: .901
.273
. 152
. .
.902-901
.596 563 for
.
.901
.
.151
851.
852-851.
)) asin (x ( 859.
) assert ( 857.
)( .6
.6 assert
.857
) assign ( : 234 331 .
.877 876
)=( 22
) =( .876
849.
228.
930

157-156
)= =( 890
166-162 191
.651
.177-176 C .293
488 .439
.422
849.
.161-159 156-154
877 876
24-22
.785-774
:
782-780 map / multimap
.776-775 set / multiset
785.
.774
: 782 map / multimap
.777-776 set / multiset
785.
.774
.842
.775 774
)( 775
849.
)*( . :
)*=( : 849.
14.
) at ( : 221 234 .
)) atan (x ( 859.
24
) AVL ( 676 700-675.
.678
.698-694
.698
699 678
.677
.698-679 678
. ) .(AVL
.700
.711
) ( 692-685 698-697 696 695 685 683 682-681
692-690 .690-685
931

.678
B
) back ( .309 296
.324
) back (
221 234 331 .
492.
) back( 471 470
.488 487
.482
.795 back_inserter
.399 398-391
) 678 (AVL.
.692-691 balanceFromLeft
.692 691 balanceFromRight
) | ( : 849.
) | | ( : 849.
) ( .368
.72
.75-74 71
70
.70-69

.874-872 70 68
. .
: 871-865
66.
: .72
.75-74 71
.72-71
.871
.71 68-67
. .
.72-71 69 baseClass
.391
) begin (:
228 224.
.761-760 bfTopOrder
.239
15 15-14 Big-O.
: .389-387
.103-96
932

) ( .794
654-653 667-651.
774
.AVL .AVL
.654
.655-654
.666-658 644
. .AVL
.658-656 644
.667-666
676-675.
.667-666
.711-710
.656-655
.653-652
) ( .535-529
.535 533-529
.814 813-812 531
537 535-534 533-532 531.
)( 537 537.
.535-533
.553-552
.
.640-639
.673-672
.642
/ .672-668
.710
/ 643-640
675-672
632 711-631.
644
602-595
644-643
632
647
650
649 639-638
647
646-644
651-650 650
651-650
637-632
933

632
637 633-632
638-637
. ) (
637
711-710
.
654 633-632
.643-639
) binary_search ( 815-811
5531 binarySearch
:
537 orderedArrayListType
binaryTreeType 646-644
651-646
) ( 867
8-7
) ( ) ( : 880
876 bool
889 876
: 849
890 889 876
825 bOp
8
)} {( : 878
) ( )] [( . .
)><( 77 41
)<<( " ")<(
)>>( " " )>(
.
) ( 632
734
) ( 736-734
)( 761-754
735-734 breadthFirstTraversal
bSearchTreeType 655-564
703 videoBinaryTree
: 886-885
602-596
602 buildHeap
698-694 AVL
290 289-288 284
290 288-285 284
934

) buildListBackward ( 290 289


) buildListForward ( 290 288
C
) c_str ( : 861 str.c_str
:C-string 861-860
174 C
860 172
860
861 172
180-174
861
180-174
C++ 902-875
.C++ ) (C++

:C++ 878
.4-3 C++
878
.
) ( 878
.
) ( 878
879-878
.
.

871-866 callPrint
.
55-45
) capacity ( : 225 vector
: / 859-858
857 6 cassert
164 cAssignmentOprOverLoad
166-164
935

876
849 static_cast
859-857 cctype
)) ceil (x ( 859
5 cerr
) ( 540551-594
554
876 875 char
char
876 875 char
)( 881-880
883
881

. C
) 859-857 (cctype.
) (
854 852-851

853
. C
859-857
/ 859-858
)( 881-880
863-862
883
863
. ) C (string
859-857
char

647
/
185
293 321
/ 470
936

486
481
/ 410
433 430
415
) ( 636 633-632
887 881-879 cin
882-881
879
337-336
474-473
) ( 16
44-43 37-36 33-31 26-25 20-16
26-25 16
307 114 41-40
172-169
159
103 96-95 88
114 40
.
. ) (
16
80-79 67 19 17-16
24 22-21 145-144
. )(
19 17-16
. ) ( )(
71 68-67
17
21
.
. .
. .
.
24
80 16
. )(
) ( 20 15
872
22
172-166 162-159 24-22
4 ) ) ((.
166 34 24 21-20
937

71
166
24
. this
56-55 15 4
44-40 26
166
55
87 86 22
.
. ) (
168-167 25-24
89-88
90-89
24
: 44-40
24
110114-112
113-112
. ) ( ) (
114
794-789 788
114
728-727 114
117-116
217
112

.
16 20-15 4
)( 874-872
.
85-80
.
114-112
44-43 37-36 33-31 26-25 20-16 ) 39-38
(
.
.
95-92
41-40
56-55
.
938

275
.
.
.
: )( 646 172-157
147-144
55-45
.
58-57
. :
. 144
16
.
.
95-92 classIllusFriend
) clear (
222 228 229 777 782
862 str.clear
730 clearGraph
730
886-885
862
190 clearList
35 33-31 clockType
37-36 33-31 26-25 20-17
86
41
42
) close ( 888
.
888
) (
542-541
545 543
545
860-859 cmath877
551-540
) ( 540551-549
) ( 540 549-540 545-540
547-545
555-553
) ( 539
.
939

) :( : 17
) :( : : 849 26891
) ( 885
885-884
) :( , 849
859
:
860 172 C
150
.
579-578

)( 537 538-537


)( 578 579-578

. ) (
867
: 108-103
108-103
/ . ))O(g(n
85-80
264-243
) =( 876
849
496-494

.
. ) (
:
860 C
) :( :
849
. /if ifelse
723
) ( 723
: 816-815 792
) Const (
902
25 19
876
874
940

849 const_cast
242 const_reference
902
152
198
902 25 19 25 19
.
35-30
190
: 72 75-74 71
178
. 499-498
. 33-31
71 68 75-74 71
84 34 31
31
34 75-74 71 84
294-293 321
432
84
31
227 31
35 77 75-74 33 84 34
31
483
422-421
508
785
785
493-492
462-460
785-774 237-218
.
224 begin
769 218
823 821
242-241 224-223
.Deque deque
224 end
800-798 798-796
802-800
816-815 792 824 822-821
824 822
941

800-798
785 785
785 785
.
228-227 224
233-229
842 841 357 266-265
808-806
/ 224
821-818
821-818
. deque vector
811-808
242
.Vector vector
890-889
178
:
602-596
/ 859-858
389-387
209 172-166
191-190
650
172-169
306-305
488
439
168-166
422 439
:copy 233-229
:
795-794
649 639-638
861 172 C
172-166 162-159 24-22
157-154
306-305 305-304
150-149
. )(
421 413
)copyList ( 305-304
421 413 copyStack
942

649 639-638 copyTree


)) cos (x ( 859
)) cosh (x ( 859
) count ( 823 821
: 823 821
) count_if ( 823 821
for . for
823 821
5 cout
887 889-882 cout
882
878 40 .cpp
730 729 createGraph
752 createSpanningGraph
860 cstddef
861-860 cstring
228 ct.begin
228 ct.clear 777 782
227 ct.empty
228 ct.end
228 ct.erase 777 782
777 ct.find
228 ct.insert 777 782
227 max_size
228 ct.rbegin231
228 ct.rend
227 ct.size
228 ctl.swap
776-775 ctType<elmType> ct 781-780
776-775 ctType<elmType, sortOp> ct 781-780
.
: 882
) ( 495
. customerType
510
497
.
.
) ( 351
.
) customerType ( 499-496
496
498-497
943

499-498
) customerType ( 351
) ( 723

D
:
: 675-672
.
882-881
143-139
4 ) ) ((
.
.
char int
37
)( 80-79 67 19 17-16
24 22-21
19 17-16
19 16
71 68-67
35-30 26
17
21
\)( 646 172-157
24
. ) (
.

:
.
.875 .
887
.
.
) ( 112
37
876-875
) (
83-81 dateType
:
871 159-158
322 305 294
944

7
884
: 389-387
: 883
: 884
879-878
20
876
900
877
:
. :
19 17-16
166 34 24 21-20
: 782-780 776-775 234-233 deque
330 220-219 vector
92
879 16
242-241 224-223
876
900 902 901 153-151 148
770
142 135-134 153
439
879 877-876 16
71 888-887
16 144
868-867
849
151-150
)( 209 157-156
227 35 31
647
75-74 33
731
34
294-293 321
488
432
67 16
) ( 166

35
945

899-898
.
delete
650
149
849
149
665-663 deleteFromTree
) deleteNode ( 666-665
) deleteNode ( 329-328
) deleteNode ( 303.-299
) deleteNode ( 316-315
) deletQueue(:
509 508 488 487
483-482 473-472 471
)( 806-802
194 190 189-188
:
782 map/multimap 777-776 set/multiset
666-658 644 699 678 AVL
547-545 303-299 284-282
329-327 316-315
147 470 483-482 473-472 471
509 508 488 487 605
222 229 223
461 411 410 409 439-437
420-418
. : :
)( 732
) ( 734-732 731
)( 754
733 depthFirstTraversal
] 234 deq [index
234 deq.assign
234 deq.at
234 deq.back
234 deq.front
234 deq.pop_front
234 deq.push_front
233 deque
237-233 deque
234-233
785
946

233
785
234
266-265

)*( 139 136-135
237
135-134
153
849 144
71
77-76 70-69
71
871-865
66
71 68 75-74 71
77 75-73 70-69
490-488
441-439
69
77
71 68-67
.
.
70-69
67
75-73 70 derivedClass
.
651-650 650 destroy
:
651-650 650
294 322
470 481 477 487 486
410 415 432
)( :destroyList
294 322
)( 470 destroyQueue
487 486
481 477
410 destroyStack
432
415
650 destroyTree
947

227 35
190
651-650
871 305 159-158
35
731
159
305

488
439
35
: 484-483 488
505
: 422 421 439
871
508
733-732 dft
734-733 dftAtVertex
242 difference_type
: 835-832 827
.
371
) ( 632
726 723 722 721
: 761-754
857 assert
591-590 divideList
> 789 divides<Type
591-589
539
) :( / 849
889 dowhile
37
: 12
) ( .
876 double
double
545
) " ( : 77 41
) 698-697 696 690 689-687 (AVL
692690
948

876 double
)( 881-880
882-881
881

. deq
329-318
319-318
321
329-321
321
321-319
)( 329-327
322
322
)( 327-324
: 322
. ) (
323
323
357
324-323
323-322 318

321 doublyLinkedList
321-319

) ( 509
151
153-151 148
159-158
206-198
151
219 vector
deque vector
867
.

: 871
148 149-147
157-154
149-148
149
949

:dynamic_cast 849
E
853
) ( 723 721
737
626-606
) empty (
225 227
492
461
861 str.empty

34
896
) ( 632
485
.
) end ( : 228 224
882 end1
886-885
882
875
)=( .
446 postfix
) = = ( .
"":
.infix )= =(
446 (=) postfix
> 791 equal_to<Type
)= =( )=( 890
228
177 108 98-97
772 pair
849
30-28 equalTime
) ( 7
) erase (
222 228 229 777 782
862 str.erase
862
:
:postfix 448 446
950

5
: 720
)!( : 849
)! =( .
878 .exe
478 40
: 878
879-878
84 34 31
)) exp (x ( 859
859 860
: .
.

: 878
)<<( 880 879
887 882-879 cin
178 108 101-100 100-99 87
849
888
F
)) fabs (x ( 859
) ( 368
370-369
) ( 882

700 AVL
: 383-379
.
/ 889-887
887
889 888-887
878
887

888-887
<< >> 888
887
888
/ / . /
889 888
951

878


) fill ( 798-796
) fill_n function ( 798-796
800-798 798-796
) find ( 801-800
777 782
862 str.find
) find_end (802-801
) find_first_of ( 802-801
) find_if ( 801-800
802-800
816-815 792
: 565 824 822-821
375-372
: 563-560 824-822
862

.First ) head (
) ( . ) (
.
884
884 fixed
876 float
876 875
876 875
883
: 883 884 883
)) floor (x ( 859
886-885 flush
886
539
889 loop
569 563
) for_each ( 827-825

895
896 void
153
902 901
871-865
827-825 675-672
952

. .
885-884
885
) (
239
) ( 746
) Friend ( 92
) ( 95-92
92
92
103 96-95
99-98
116
) ( 471 470
484 509 508 488 487
471 482-481
470
) front ( 296-295
324
) front ( 221 234 331
492
) front( 470
509 508 488 487
482-481
.front queueFront
795 front_inserter
887 fstream
: 789
:
75-74 71
70
390 369
895
897 896 void

:

92
)( 85 83-82 28-26 16
163-162
99 97
101
100
953

114 40
895
896 void

.
:
.
672
) ( 794-789 788
791-789
789
794
794
842
792-791 794-791
:109 85
69
114-110
673-672

26-25 16
230-229 copy
92
162
99 97
101
100
/ 7-6 796

114-110 85
114
110
5
14
15 15-14 Big-O . ) (
24
. )) O(g(n 899-898
.
. ) (
. ))30-25 7-5 O(g(n
. . .main
main . . )).O(g(n
. )(
954

896
827-825 675-672
114 901 168-167 25-24
871-865 827-825 675-672 153
422
672
7-5
7-5
.
902 25
.
. ) (
. .
. .
840-796 788-786
) 863-861 861 (string
.
. void .
.
871-867
.Void void
G
391
) generate ( 800-798
) generate_n ( 800-798
800-798
.
727 getAdjacentVertices
505 getFreeServerId
) getline ( 861
505 getNumberOfBusyServers
: 890
391
264-243
736-731
736-734
734-732 731
721 763-719
.726
730
723
730-729
955

723
731
736-735 729-728
731
726 723 722 721
.723 721
754-744
731
763-762
726 725-723
743-738 738-737
723
721
746 737 723 721
.731
746
722 721
737 721
.
.737
graphType 736-735 729-728
731-729
755-754 topologicalOrder
" " )<(177
772 pair
849
" " )<=(177
772 pair
849
" " )<<( .
> 791 greater<Type
> 792 greater_equal<Type
) (743-738 738-737
. ))O(g(n
H
40 .h
" ."has-a
539-538
539
538
550
. ) (
956

539-538
550 547-545
550
552-538
.
549-547
545
539-538
.
552-551
555-553
542
. .
) head (279-278 276 274
275
878-877 863-875
307 114 41-40
77
40
) (41
789
878-877 77 41-40 :79-78
41
318-316
494
460 439 423

) (358-357 336-335

788

605-595 494
602-596
605-604
605
604-602
605 602 heapify
595
602-596
606-605
604-602
638-637
) hieght (638
957

. AVL
44-40 26
.C++ 878 C++
.4-3
428-425
.
859 860
)> :(- 849 145-144
I
/ ) /(
/ 889-887
887 877 iostream
) (
:
879 16
890
26
)( 892-891

56-55
56-55 15 4
56-55 4
889 if
889 if else
887 ifstream
:44-40 26
92 42 40
114
40
878-877 #
) includes (829-827
878-877 77 41-40
:79-78
)879 86 (+ +
237
849
151-150
for . for
. .
371
.
)! =(
958

228
178-177
772 pair
849
371
441 infix
442 postfix
441 infix
44-40 26
4 80-66
66
80 67
264-243
80
80-79
115
71 68-67
66
)(67-66
:
)( ) initializeList (
295-294 322
)( ) initializeQueue (470
488-487
481-480 477
)( ) initializeStack (410
432
414
:
901 481-480
414
: 782-780 map / multimap -775 set / multiset
776
166
: 234-233 deque 330 220-219 vector
)(35-30 26
295-294 294-293
322
147
470 481-480 477 488-487
410 414 432
: 16
) inner_product (839 838 835
959

) inorder (643-642
) (643-640 639
673-672
642
/ 669-668
/ 643-640
) inplace_merge (817
:
6
) (
882-881

352-351
888
238
. cin
: 882
) (881-879
881-879 cin
55
889-887
.
861
) insert(549
) insert(194-193
) insert (658-657 656
698 AVL
) insert (
222 228 229 777 782 795
863-862 str.insert
796-794
) insertAt(188-186
) insertEnd(188
795 inserter
) insertFirst (299 298-297 290
863-862
:
194-193 188-186 537-535
:
777-776 set / multiset 782 map / multimap
698-679 678 AVL
658-656 644
233 deque
960

336-335 299-297 282-279


327-324 336-335 314-31 309
605
222 221 219 vector 223 223-222

694-692 insertIntoAVL
)>>(882
887 889-882 cout
323-322 295 178 106-105 100-99 87 86
849
888
:
572-566
577-573
578
572 insertionSort
) insertLast (299-298 290
:insertNode
327-325
314-313
537-536 insertOrd
:
537 orderedArrayListType
114
876 875 int
int
int
876 875
)( 881-880
882-881
881

:
876 875
370-369 368
char int
876 875
.
721
832-829 827
882-881
34
75-74 71
961

84
/ ) /(
/ 889-887
887 877 iostream
) (
887 877 iostream
" ."is a
)) isalnum (ch ( 857
)) iscntrl (ch ( 857
)) isdigit (ch ( 858
) isEmpty (186-185
) isEmpty (647
) isEmpty (729
)( : isEmptyList
293
321
)( :470 isEmptyQueue
486
481
)( :410 isEmptyStack
433
415
: isFull 186-185
)( :470 isFullQueue
486
481
)( :410 isFullStack
433 430
415
)) isgraph (ch ( 858
)) islower (ch ( 858
)) isprint (ch ( 858
)) ispunct (ch ( 858
)) isspace (ch ( 858
243-242 istream
)) isupper (ch ( 858
)) isxdigit (ch ( 858
) iter_swap (811-808
.
243-237 223 218
239
785
242-241 224-223
962

239
241
238
796-794
243-242 istream
238 237 239 240
243 ostream 233-231 copy
238
842 266 265
240
243-242
242-241 223 typedef
237
J
902-875 C++
885
K
) (524
667
537 535-534 533-532 531
604
578
595
586
578 566
537 535 528-527
) (654
) (:
539 538
524
) (
.
720
L
:
20

109 larger
112-110
: 565
963

824 822-821
375-372
375-373 largest
859
) ( . ) (
.
) (637
)>( . " "
)=>( . " (
)>>(
885 left
) 698 696 689 686-685 (AVL
692-691 690
885
391
) length (322
) length (295
) length (:
862 str.length
:
:C 861
:295
180
" " )>(
775 774
177
772 pair
849
494
" " )>=(177
772 pair
849
" ") >> ( .
> 792 less<Type
> 792 less_equal<Type
) 877 (C++
.
.
667-666
) (542-540
551
.
.
964

.
357-273
726 725-724
293-290 307-290
631
3337 336 290 278
307
290 289-288 284
290 288-285 284
/293
337-336
307-293
306-305
306-305 305-304
352-351
294-293
293-290
)( 303-299 284-282
490-488
441-439
294
305
591-589
.
631
279-278 276 275 274 Head
header358-357 336-335 trailer
295-294 294-293
)( 336-335 299-297 282-279
:295
. ) (
.
295
306 293
457-453 289 285 279-278 278-276
279-278 276 275 274 head
357-337
278-275
358-357
348-345 303 302 297-296
: 577-573
595-587 565
279-278
965

218
488-484
509 508 487
486
486
485-484
509 508 488 487
490-488
487 486
484 509 508 488 487
488-487
488-486
487 486 484
484 488 487
491
441-428
436-433
439
433
433 430
439
439
432
439 430-429
441-439
432
439
/ 431
439
432
439-437
429 439-437 437
577 linkedInsertionSort
726 linkedListGraph
726 linkedListType
306-305
294-293
293-290
305
726 linkedListGraph
490-488 linkedQueueType
441-439 linkedStackType
307-293
966

345 343 videoListType



linkedQueueType
485-484
490-488 linkedListType

linkedStackType
432
430-429
linkedListType441-439

) (274
276 274 NULL
330 list
335-330
330
785
785
332-331 335-331
357
)(330
:
: 195
) list (414
198-180

330 list<elementType>listCont
331 listCont.assign
331 listCont.back
331 listCont.front
332 listCont.merge
331 listCont.pop_front
331 listCont.push_front
331 listCont.remove
331 listCont.remove_if
332 listCont.reverse
967

332 - 331 listCont.sort


331 listCont.splice
331 listCont.unique
180
.
209 181-180
39-38 38-37 114-112
.
180
.
: 195
.
.
.

listType 39-38
arrayListType
113-112 listType
)) log (x ( 859
)) log10 (x ( 859
) 889 876 (Boolean
) :(Boolean 849
794
) 890 889 876 (Boolean
> 794 logical _and <Type
> 794 logical _not <Type
> 794 logical _or <Type
875 long
876 long double
889
) (441

968

M
40 main
879-878
. :
774-772 make_pair
)(882
886-885 882 end1
884 fixed
886-885 flush
885 left
885 right
884 scientific
883 setprecision
885-884 setw
884 showpoint
770 map
785-780 map
782-780
785
782
785
781 780
)(780
) 860-859 (cmath
: 724-723
) max (821
) max_element (824 822
) max_size ( : 225 227
) ( )22 21 (.
849 144
)>145-144 (-

969

849
) 17 ( :
80-79 19 16
67 16
. )(
) ( ) ( 114
228-227 224
229-228
) ( )( 80-79 67 19 17-16
19 16
30-28 24 22-21
190-185 arrayListType
.
651-646 binaryTreeType
867
166-164 cAssignmentOprOverLoad
25 19 const
499-498 customerType
85 83-82 28-26 16
:114 40 :

731-729 graphType
30-25
71 68-67
307-293 linkedListType
17
21
103 96-95
98-96
172-170 pointerDataClass
147-145

970

293 19
24
507-504 serverListType
502-501 serverType
703-702 343-341 videoType
871-867
509-508 waitingCustomerQueueType
:
/ 84
85-80
84
. )(
) ( .
21
390
: .
) merge (817-816
332

595-587
595
594-593 mergeList
594 mergeSort
/ 817-816 594-591
539
) min (822
) min_element (824 822
754-744
753-752
749
753-752 minimalSpanning

971

563 minLocation
) :( -
849
) ( -
849
.
20
) .( - -
> 789 minus<Type
) ( 787 788-787
4
) :(% 849
> 789 modulus<Type
517-494
509-496
512-511
511 510
512-510
495
. :

517-512
511-510
496
:msTreeType 752
770 multimap
785-780 multimap
782-780
785
782

972

785
781 780
)(780
66
) * (107
849
> 789 multiplies <Type
780-775 multiset
776-775
785
777-776
785
776 775
)(775
) (788-787
N
n 398-392
876
/ NULL ) 860 147 (NULL
861 string : : size_type
:
152
31
35
.
41
87
895-890 namespace
:namespace )(892-891
891-891 namespace

973

890
859
857 6 NDEBUG
> 789 negate<Type
new
153-151 148
149-147
849
148
) :(\ n 880
180-174 172 newString
) 678 (AVL
678 struct
) ( .AVL ) (AVL
: 654
637
/642 636
. .
636 struct
642
637 633-632
675-672
) (278-274
276 274
280-279
322 305 294
279 275
:303-299 284-282
329-327
316-315
: 327-324

974

298-297 290
299-298 290
314-310 309
:295 308
:279-278 277
:296-295
324
296
324
) ( :435-434
.
) ( 787 787-786
) (
852-851
: 460-452
669 nonRecursiveInTraversal
672 nonRecursivePostTraversal
670 nonRecursivePreTraversal
" " .
) ! ( : 849
> 791 not_equal_to <Type
.Npos string : : npos
398-396 nQueensPuzzle
) NULL (860 147
)860 147 (NULL /.
) ( #
446 postfix
877
20
:
108-103

75

.
383-379
char int
) (839-835 788
.
O
))) O(g(n /( 15 15-14
537 538-537
578 279-578 586 595
195 307
423
878 .obj
) (878 40
:878
4
4 4 .85
. 55

.
4
.
887 ofstream
900
902
900 902 901
153-151 148
. ) (
.
901

976

198-180
902-901

: 889 if
.OOD
.OOP ) (4

=) op ( : 849
) ( 540 549-540
545-540
547-545
554-553
) open (888

889 888
) (4
12
44-40 26
56-55 4
37
87 :
180-174 C
103 96-95 88
103 98-96
87
103 99-98
87
* :operator
173-172 103-86
99-96
173-172

977

:166-162
191
651 177-176 C 306 293
488 439
422
103-96
178 108 101-100 100-99
.
323-322 295 178 106-105 100-99
:87-86
855
855 88
703-702 626-606 180-174 108-103
116-115
703-702 178-177 99-96
)(96-95 88
103
*107 operator
] [ 177 173-172 operator
= 651 488 439 422 306 293 177-176 166-162 operator
= = 177 108 98-97 operator
= ! 178-177 operator
>177 operator
=>177 operator
>>178 108 101-100 100-99 operator
<177 operator
=<177 operator
<<323-322 295 178 106-105 100-99 operator
) ( 789 operator
109 98-97 operator+
:

978

. .
.
.
.
849
.
87 86 22
849 876
.
149 delete
.
.
.
.
.
. ) (
849 145-144
17
153-151 149-147 new
.
. )(
.
849 26 891
.
96 95 OpOverClass
.103-101
) | | ( : 849
) /( . ))O(g(n
. )(
529
537-535

979

318-307
336 308-307
316-309 308
308
)( 316-315
318-316
)( 336-335 314-310 309
817-816 594-591
. ) (
308
460-452 379-376
310-309
orderedArrayListType 529
564 537
orderedLinkedListType 308
318-316

243 ostream
233-231 copy
)(901
:
.
.
:888
238
.
. cout
: 886-885

886-885
885-884

980

889-882 cout
889-887
295 323
308
) (550 539
) ( 418-417
:
789
.
.
70-69
P
774-770 769 pair
772 771
)(770
772 pair
) (
772-771
774-772
770
) (723
.
. :
) ( : 112 )(
.
: 899-898
.
.
510
) (637-632

981

)) ((
441
849
34
896
) partial_sum (839-838 835
585 partition
.
585-580
77-75 partTimeEmployee
:
728-727 114
114 902-901
168-167 25-24
871-865 827-825 675-672 898 153
422
84
) ( 637
) ( 723
743-738 738-737
723
737
) :(% 849
676-675
) ( .
85-83 personalInfoType
personType 351 customerType
90-89 44-43
91-90
75 partTimeEmployee
) pivot (585 584 583 582-580

982

) :(+ 849
)(+
.
849
20
) .(+ +
> 789 plus<Type
) :(=+ 849
207 151
)(:
)(646 172-157
134 133
242 pointer
.
158-157 pointerDataClass
172 170-169 167-166
159-158
172-170
134 151-134
/ 145-144
151
143-135 / 642 636
147-145
150
152
150-149
)( : )( 646 172-157
142 135-134
153
153-151 148
151-150

983

209 157-156
159-158 153-151 148
149-147
672
151-150
147
457-453 289 285 279-278 278-276
279-278 276 274 head 279-278 277
487 486 484
143-139
151-149
153
869-868
471
477 473 471 475
209-207
154
638 156-154
414
143-135
89-88 this
159

511
441
4

: 206-198
) pop ( 492
461 411 410 409
439-437 420-418

984

) pop_back ( : 222 229


) pop_front ( : 234 331
)( 6-5
7-6
462 446-441 postfix
446 441
446-442
442 postfix
442 infix
452-446 postfix
448 446
448-447
446
452-449
/ 452
446
462 441 postfix
postfix
/ : 849
) postorder ( 643
) ( 640
642
/ 672-671
643
)(#
446 postfix
877
)) pow (x, y ( 860
)( 849
849 144
144

985

)(:
883
)( 6-5
7-6
760 759 758 757 756 755 predCount
857 859-857 860-859
)( 878-877
) ( 794
441 prefix
/ : 849
( preorder ( 640
) ( 640
642
/ 670
643
878 878-877
77
857 NDEBUG
877
.
) ( 542-541
545 543
) print ( 186
871-865 (baseClass/ derivedClass) print
731 printGraph
: 186
323
731
295 323
460-452 379-376
754-753

986

:print:istReverse 379-378
743 printShortestDistance
printTreeAndWeight
606-605 494-493

) priority_queue (494
80-79 17 16
.
19
293 19
71 68-67
20
17
874-872 70 68
95-92
19
874
19
80 67
y 511
) (
545
540
544-543 543-542
542
:
389-372
390
4-3

987


879-878



:
4
903
:
206-198
55-45
55-45
108-103
264-243
206-198
626-606
264-243
428-425
264-243
357-337
180-174 newString
703-702 626-606 180-174 108-103
206-198
626-606
428-425
264-243 vector
709-701 357-337
:
.
4
) ( .C++ C++ 7

988

.4-3
8-3 2
.
7-5
2
2
3
879-878
.
293 185 80-79
20
80
80-79 17 17-16
24
19
68-67
20
80-79
) push (:
492
461 411 410-409
436-433
418-415
) push_back ( :
222 223-222 229 795
) push_front ( : 234 331 795
Q
) ( 545-542
549-547
552

989

545-543
) :(: 849
) queue ( ) ( 493-492
492
494
471 queueFront
487 486 484
477 473 471 475
471 queueRear
487 484
477 473 471 475
470 517-469
471 470
.
471-470
/ 470
495

493-492
470
. deque
.
471 470
470
) ( 785 494
470
605
.
.
471
606-605 494-493

990

517
471 470
471
470 470
509
469 218
484-471
482 472-471
475-473
/ 481
474-473
483
477
480-478
483-482 473-472 471
481 477
484-483
478-475
471
482-481
481-477480
477 473 471
475
471
482
queueType 480-478

508-507 waitingCustomerQueueType
495
496-495

991

:
842
711-710
117-116
58-57
842 841 357 266-265
266-265 deque
116
842
763-762
115
842 266 265
358-357
357
116-115
209-207
517
399-398
555-552
357 266-265
57-56
626 555-552
462
843-842 841
116
265 vector
:
586-579
605
586
586 QuickSort

992

.
R
) RAM (

240
) ( 542
545
) random_shuffle ( 824 823-822
) rbegin ( : 228231
. cin
.
) ( 471 470
484 488 487
471
482
.rear queueRear
594 recMergeSort
.AVL AVL
. structs
586 recQuickSort
368 377-369
.
369-368
/ 371
.
371
390
389-372
399-398
373-372 369

993

399 398-391
369-368
390 369
390-369
height 638
390 369
371
383-379
375-372
390
594
379-376
389-372
586
387-383
70-69
)&( 901 897 896 153
153
897898-897
.
153
902-901
25
868-865
153
901 897 896 153
898
242 reference
542
:reinterpret_cast 849
889

994

703-702 178-177 99-96


772 771 pair
849
792-791 794-791
)(%
849
) remove( 194
) remove ( 806-802
331
) remove_copy ( 806-802
) remove_copy_if ( 806-802
) remove_if ( 806-802
331
) removeAt( 189-188
. )(
) rend ( 228
)( 889
390
) replace ( 808-806
863 strl.replace
) replace_copy ( 808-806
) replace_copy_if ( 808-806
) replace_if ( 808-806
) replaceAt( 189
808-806
189
863
)( 3
: 847
) resize (:
222 vector 229

995

) retrieveAt( 189
:
189

) (:
874 const
154
898 770
:
90-89
) ( 296-295
324
) ( 470
509 508 488 487
482-481
. ) (:
) ( 296
324
874-872
) ( :471
488 487
482
862
) ( 461 437 411 410 409
437
) reverse ( 821-818
332
. postfix
) reverse_copy ( 821-818
: reversePrint
323

996

378-376
821-818
)<( . " "
)=<( . " "
)<<( .
885 right
) 698 696 695 689 686-685 (AVL
692 691-690
) ( 632
: 654
636
) ( 746
) rotate ( 821-818
) rotate_copy ( 821-818
690 rotateToLeft
691 690 rotateToRight
692-685 AVL
698-697 696 695 685 683 682-681
692-690
690-685
821-818
867
:runSimulation 512-511
S
884 scientific
)( :
884 883
: 24
) 891 26 ( : :
849

997

:555-523
656-655
535 533-529
13-12
. ) (
) (:
537 537538
) 1 (
523
535-533 528-527 13 12
555-552
527-526 348 302 297-296 192-191
:
) search ( 656 655
) search ( 297-296
) search ( 815-811
:
656-655
814 813-812 531
815-811
348 303 297-296 193
) search_n ( 815-811
.
:
656-655
550
.

: .
193-191
.

998

348-345 303 302 297-296


310-309
) ( 545
: / / 889-887
: 889
:
566-560
565
578 566
565-564
564 selectionSort
564 orderedArrayListType
):( ,
16
877
) | ( : 849
229 seqCont.clear
229 seqCont.erase
229 seqCont.insert
229 seqCont.pop_back
229 seqCont.push_back
229 seqCont.resize
194 139 seqSearch
335-330 237-233 227-218
785
785
229-228
357 266-265
.219-218 deque vector

) :( , 849

999

.
527-526 348 302 296 192-191
193-191
348 303 297-296 193
537 535 528-527
303 302 297-296
535 528-527
552
) ( 503-502 495
. serverListType
503
) ( 495
. serverType
.
510
.
499
:507-502 serverListType
504
502
504-503
505
507-504
:502-499 serverType
499
501-499
502-501
780-775 set
776-775
785
777-776

1000

785
776 775
)( 775
: 835-827
721
) set_difference ( 835-832 827
) set_intersection ( 832-829 827
) set_symmetric_difference ( 835-833 827
) set_union ( 832-830 827
498 setCustomerInfo
883 setprecision
setw 885
506-505 setServerBusy
510 setSimulationParameters
885-884 setw
)( 638 209 208 168-166 161-159 156-154
650 639-638 170-168 161 157-156
875 short
) ( :737
743-738 738-737
743-742
743-742 shortestPath
884 showpoint
824 823-822
.
.
876-875
) ( .
: 881-880
char double
int string

1001

723
) ( 723
)( 494

:\ 510
)) sin (x ( 860
66
)) sinh (x ( 860
) size ( 225 227
492
461
862 str.size
. size_type string : : size_type
242 size_type
sizeof 849
) .( /
) :(=/ 849
:
563-560
824 822
:
859
:2-1

2
15-2 57-56
:626-559
579-578
604-595
578-566

1002

595-587
) (:
578 579-578
605-604 595 586 578 566
626-606
626 555-552
586-579
566-560
) sort ( 815-811
332-331
:
604
577 572
594-593
:815-811
332-331
586-585
564-563
:
.
: 605-595
572-566 586-579
566-560
.
: 577-573
595-587 565
) ( 878
: 878
737
) ( ) ( : 880
) ( 746 745

1003

752
754-744
.
44-40
.
) splice (:
331
)) sqrt (x ( 860 :
)] [( .
860
) stack ( ) ( 462-460
461
460 439 423
439
422
409 462-407
411 410-409
.
410
423
/ 410
462-460
421 413
439
410
.
446-442 postfix
439 423 785 460
410
.
.

1004

:postfix
452-446
428-425
462
411 410 409
409-408 411 410 409
461 411 410 409
442 408 218
424-411
418-415
422
: 423
415
415
422-421
422
413-411
415
422 421
423
414
418417
414
428-425
420-418
424
:429 413 411
420-418
420
429 413 411 stackTop
:stackType

1005

413-411
423

5
.
879
882
STL
:
:857 assert
.
:
879-878
. cin
891-890 namespace
. cout
151
867
24
876 static_cast
849
895 std
893 892 std : :
4
) STL ( 844-769 264-217
769 219-218
217

) ( 840-789
786
840-796

1006

789
794-789 788
796
788
788-787
788-787
787 787-786
839-835 788
843-842 841
. ) (
861 str.c_str
862 str.clear
861 str.empty
862 str.erase
862 str.find
862 str.insert
862 str.length
862 str.size
862 str.substr
862 (str2) str1.swap
) strcat ( ) 860 (C
) strcmp ( ) 860 (C
) strcpy ( ) 861 (C
: 887
. )<<(
. )>>(
243-242
ostream
:
:Cin cin
:Cout cout

1007

888-887
861 string : : npos
861 string : : size_type
) 863-861 861 (string
C
863-861 861 string
:string
883
862

) :(string
861
862
862
863-861 861
)( 861
863-862
883
863
862
C string
) strlen ( 861
723
.struct structs
:struct 145-144
144 struct
structs
678 AVL
636
144
. struct

1008

275
147-144
strct
.
structs
4
4
. structs
721
.
) substr ( : 862 str.substr
:
862
862
) :( - 849
) ( 654 632
. postfix
) swap ( 811-808
228
) 862 str1.swap (str2
) swap ( 585 563
) swap_ranges ( 811-808
811-808
585 563-561
862 string
889 switch
.
: 835-833 827
:
896
896 void

1009

877
879 cin
21
112
16
170
882 cout
34
149 delete
67
886 flush
: 895
896 void
: 895 896 void
110
242 istream
885 left
876
890 namespace
148 new
900
888 open
87
243 ostream

/ 163-162

/ 99 97

/ 101

1010

/ 100
134
877
885 right
883 setprecision
110
885 unsetf
891 namespacename / using namespace
896-895
877
897-896 void
:
)><( 41
878-877 77 41
. )(
T
880
371
)) tan(x ( 860
)) tanh(x ( 860
114
110 85
114-110
116
110

509
7
:8-7
6 assert
8-7

1011

8 7
.
89-88 this
:throw 849
) :(- 35
. ))O(g(n
496
.
)) tolower (ch ( 858
) ( 409-408
429 439-437 437
411 410 409
461 411 410 409
429 413 411
420-418
) top ( 461 437 411 410 409
4
)( 761-754
761-754
754
760 759 758 757 756 754 topologicalOrder
755-754 topologicalorderT
)) toupper (ch ( 859
390 387-383
) trailer ( 358-357 336-335
: 884
) ( 495506-505 503
510
) transform ( 827-825
.
:

1012

.643-639
.731
279-278 323-322 318
:
. .746 745
859 860
: 889 ifelse
37
242-241 Typedef const_iterator
242 Typedef const_reverse_iterator
241 223 Typedef iterator
:Typedef
242 Reverse_iterator
242-241 223 typedef
242
typeid 849
U
20
:
103
849
) ( 794
) ( 420
)_( 890
722 721
20
721
832-830 827
) unique (:
331

13

) unsetf ( 884
885
507-506 updateServers
509 -508 updateWaiting Queue
675-672
.
.

. void

:
77 41-40
)( C++
892-891
878-877
895 892-891 using namespace / namespacename
891
772 770 utility
V
6
897897
25 19
153
168-167 25-24
871-869
153
896
857 6 assert
895
859-857

1014

895
860-859
898
: 874 const
154 898 770
: 861-860 C
863-861 861 string
896-895
void 898
242 value_type
:
8
.
. ) (
. under

:
877 876
. )(
879 877-876 16
888-887
16
144 struct
149-147
888-887
16
.
181
.
143-135
.

1015

char double
int string )(
] 221 vecCont [index
221 vecCont.at
221 vecCont.back
225 vecCont.capacity
222 vecCont.clear
225 vecCont.empty
222 vecCont.erase
221 vecCont.front
222 vecCont.insert
225 vecCont.max_size
222 vecCont.pop_back
222 vecCont.push_back
222 vecCont.resize
225 vecCont.size
219 vector
:227-219 vector
221 219
223-221
220-219
242-241 224-223
222 221223
785
222 221 219223
223-222
785
233-229
264-243
265
225

1016

222
:
.vector vector
) ( 721
726 723
734
723
732
731
729
737
761-754
) ( 350-343
) ( 703-701 343-338
709-701 357-337
706-703 videoBinaryTree
703 bSearchTreeType
704-703
706-704
) videoListType ( 350-343
345 343 linkedListType
:videoType
702-701 341-339
703-702 343-341
871
:
867
868-867
871-867
:void
896

1017

897 896
896
898
.
898-896
896-896
W
) ( 508-507 495
508
. waitingCustomerQueueType
509
509-507 waitingCustomerQueueType
508
508
508
509-508
508-507 queueType
391
737
737
743-738 738-737
737

) ( 746
754-753

738-737 weightedGraphType
738 weightFound bool
889 while
8 7

1018

: 880
.

1019

You might also like