+ All Categories
Home > Education > Documentation - LibrarySorting

Documentation - LibrarySorting

Date post: 21-Jun-2015
Category:
Upload: michel-alves
View: 178 times
Download: 0 times
Share this document with a friend
Description:
Class that implements the strategies of sorting: BubbleSort, BubbleSort2, GnomeSort, ShakerSort, CombSort, InsertionSort, SelectionSort, QuickPivotCentral, QuickPivotPeripheral, MergeSort, ShellSort, heapsort, and InternalQuickSort.
Popular Tags:
95
Reference Manual Generated by Doxygen 1.6.3 Sun Dec 4 13:13:28 2011
Transcript
Page 1: Documentation - LibrarySorting

Reference Manual

Generated by Doxygen 1.6.3

Sun Dec 4 13:13:28 2011

Page 2: Documentation - LibrarySorting

Contents

1 Class Index 1

1.1 Class Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

2 Class Index 3

2.1 Class List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3 File Index 5

3.1 File List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

4 Class Documentation 7

4.1 AbstractSorting Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

4.1.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4.1.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 8

4.1.2.1 AbstractSorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4.1.2.2 ∼AbstractSorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4.1.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4.1.3.1 ComparisonsNumber . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4.1.3.2 InitializeVariables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4.1.3.3 InversionsNumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4.1.3.4 IterationsNumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4.1.3.5 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4.1.4 Member Data Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4.1.4.1 _numero_de_comparacoes . . . . . . . . . . . . . . . . . . . . . . . . 10

4.1.4.2 _numero_de_iteracoes . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4.1.4.3 _numero_de_trocas . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4.2 BubbleSort Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

4.2.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

4.2.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 13

4.2.2.1 BubbleSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Page 3: Documentation - LibrarySorting

ii CONTENTS

4.2.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4.2.3.1 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4.3 BubbleSort2 Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

4.3.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

4.3.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 16

4.3.2.1 BubbleSort2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

4.3.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 16

4.3.3.1 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

4.4 CombSort Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

4.4.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

4.4.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 20

4.4.2.1 CombSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

4.4.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 20

4.4.3.1 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

4.5 Element Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4.5.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4.5.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 22

4.5.2.1 Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4.5.2.2 ∼Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4.5.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4.5.3.1 operator< . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4.5.3.2 operator<= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

4.5.3.3 operator> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

4.5.3.4 value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

4.5.3.5 value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

4.6 ElementVector Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

4.6.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

4.6.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 25

4.6.2.1 ElementVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

4.6.2.2 ∼ElementVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

4.6.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 26

4.6.3.1 absMaxValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

4.6.3.2 add . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

4.6.3.3 at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

4.6.3.4 clear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

4.6.3.5 isEmpty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 4: Documentation - LibrarySorting

CONTENTS iii

4.6.3.6 maxValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

4.6.3.7 minValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

4.6.3.8 operator[] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

4.6.3.9 push_back . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

4.6.3.10 resize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

4.6.3.11 size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

4.6.3.12 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

4.6.3.13 swap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

4.7 GnomeSort Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

4.7.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

4.7.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 34

4.7.2.1 GnomeSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

4.7.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 34

4.7.3.1 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

4.8 HeapSort Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

4.8.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

4.8.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 38

4.8.2.1 HeapSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

4.8.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 38

4.8.3.1 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

4.9 InsertionSort Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

4.9.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

4.9.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 41

4.9.2.1 InsertionSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

4.9.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 42

4.9.3.1 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

4.10 InternalQuickSort Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

4.10.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

4.10.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 44

4.10.2.1 InternalQuickSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

4.10.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 45

4.10.3.1 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

4.11 MergeSort Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

4.11.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

4.11.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 48

4.11.2.1 MergeSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 5: Documentation - LibrarySorting

iv CONTENTS

4.11.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 48

4.11.3.1 MergeMethod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

4.11.3.2 Merges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

4.11.3.3 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

4.12 PredicateSort Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

4.12.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

4.12.2 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 51

4.12.2.1 operator() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

4.13 QuickPivotCentral Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

4.13.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

4.13.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 54

4.13.2.1 QuickPivotCentral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

4.13.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 54

4.13.3.1 QuickSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

4.13.3.2 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

4.14 QuickPivotPeripheral Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

4.14.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

4.14.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 58

4.14.2.1 QuickPivotPeripheral . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

4.14.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 58

4.14.3.1 Partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

4.14.3.2 QSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

4.14.3.3 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

4.15 SelectionSort Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

4.15.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

4.15.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 61

4.15.2.1 SelectionSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

4.15.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 62

4.15.3.1 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

4.16 ShakerSort Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

4.16.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

4.16.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 64

4.16.2.1 ShakerSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

4.16.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 65

4.16.3.1 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

4.17 ShellSort Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 6: Documentation - LibrarySorting

CONTENTS v

4.17.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

4.17.2 Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . 69

4.17.2.1 ShellSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

4.17.3 Member Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 69

4.17.3.1 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

5 File Documentation 71

5.1 Element.cxx File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

5.2 Element.cxx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

5.3 Element.h File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

5.4 Element.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

5.5 SortingAlgorithms.cxx File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

5.6 SortingAlgorithms.cxx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

5.7 SortingAlgorithms.h File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

5.8 SortingAlgorithms.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

5.9 Sys-LibrarySorting.cpp File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

5.9.1 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

5.9.1.1 ExecuteSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

5.9.1.2 main . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

5.10 Sys-LibrarySorting.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 7: Documentation - LibrarySorting

Chapter 1

Class Index

1.1 Class Hierarchy

This inheritance list is sorted roughly, but not completely, alphabetically:

AbstractSorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7BubbleSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11BubbleSort2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14CombSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18GnomeSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32HeapSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36InsertionSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40InternalQuickSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43MergeSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46QuickPivotCentral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52QuickPivotPeripheral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56SelectionSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60ShakerSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63ShellSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22ElementVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25PredicateSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

Page 8: Documentation - LibrarySorting

Chapter 2

Class Index

2.1 Class List

Here are the classes, structs, unions and interfaces with brief descriptions:

AbstractSorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7BubbleSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11BubbleSort2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14CombSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22ElementVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25GnomeSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32HeapSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36InsertionSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40InternalQuickSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43MergeSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46PredicateSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51QuickPivotCentral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52QuickPivotPeripheral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56SelectionSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60ShakerSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63ShellSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

Page 9: Documentation - LibrarySorting

Chapter 3

File Index

3.1 File List

Here is a list of all files with brief descriptions:

Element.cxx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71Element.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73SortingAlgorithms.cxx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76SortingAlgorithms.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84Sys-LibrarySorting.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

Page 10: Documentation - LibrarySorting

Chapter 4

Class Documentation

4.1 AbstractSorting Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for AbstractSorting:

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

BubbleSort

+ BubbleSort()+ sort()

BubbleSort2

+ BubbleSort2()+ sort()

CombSort

+ CombSort()+ sort()

GnomeSort

+ GnomeSort()+ sort()

HeapSort

+ HeapSort()+ sort()

InsertionSort

+ InsertionSort()+ sort()

InternalQuickSort

+ InternalQuickSort()+ sort()

MergeSort

+ MergeSort()+ sort()+ MergeMethod()+ Merges()

QuickPivotCentral

+ QuickPivotCentral()+ sort()+ QuickSort()

QuickPivotPeripheral

+ QuickPivotPeripheral()+ sort()+ QSort()+ Partition()

SelectionSort

+ SelectionSort()+ sort()

ShakerSort

+ ShakerSort()+ sort()

ShellSort

+ ShellSort()+ sort()

Public Member Functions

• AbstractSorting ()

• void InitializeVariables (void)

• long double IterationsNumber (void)

• long double InversionsNumber (void)

• long double ComparisonsNumber (void)

• virtual void sort (ElementVector &ev)=0

• virtual ∼AbstractSorting ()

Protected Attributes

• long double _numero_de_iteracoes

• long double _numero_de_trocas

• long double _numero_de_comparacoes

Page 11: Documentation - LibrarySorting

8 Class Documentation

4.1.1 Detailed Description

Classe base para uso do padrão strategy.

Definition at line 17 of file SortingAlgorithms.h.

4.1.2 Constructor & Destructor Documentation

4.1.2.1 AbstractSorting::AbstractSorting ()

Constructor

Definition at line 16 of file SortingAlgorithms.cxx.

00017 {00018 InitializeVariables();00019 }

Here is the call graph for this function:

AbstractSorting::AbstractSorting AbstractSorting::InitializeVariables

4.1.2.2 virtual AbstractSorting::∼AbstractSorting () [inline, virtual]

Método destrutor. Responsável por liberar todos os recursos alocados.

Definition at line 78 of file SortingAlgorithms.h.

00078 {}

4.1.3 Member Function Documentation

4.1.3.1 long double AbstractSorting::ComparisonsNumber (void) [inline]

Método que retorna o número de comparações realizadas entre elementos da lista de Elementos.

Definition at line 68 of file SortingAlgorithms.h.

00068 { return _numero_de_comparacoes; };

Here is the caller graph for this function:

AbstractSorting::ComparisonsNumber main

4.1.3.2 void AbstractSorting::InitializeVariables (void)

Método que executa a inicialização das variáveis de estado da classe para posterior avaliação do desem-penho dos algoritmos utilizados.

Definition at line 26 of file SortingAlgorithms.cxx.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 12: Documentation - LibrarySorting

4.1 AbstractSorting Class Reference 9

00027 {00028 _numero_de_iteracoes = 0;00029 _numero_de_trocas = 0;00030 _numero_de_comparacoes = 0;00031 }

Here is the caller graph for this function:

AbstractSorting::InitializeVariables AbstractSorting::AbstractSorting

4.1.3.3 long double AbstractSorting::InversionsNumber (void) [inline]

Método que retorna o número de trocas ou mudanças de valor entre posições dentro da lista de Elementos.

Definition at line 62 of file SortingAlgorithms.h.

00062 { return _numero_de_trocas; };

Here is the caller graph for this function:

AbstractSorting::InversionsNumber main

4.1.3.4 long double AbstractSorting::IterationsNumber (void) [inline]

Método que retorna o número de iterações realizadas pelo último algoritmo de ordenação executado.

Definition at line 56 of file SortingAlgorithms.h.

00056 { return _numero_de_iteracoes; };

Here is the caller graph for this function:

AbstractSorting::IterationsNumber main

4.1.3.5 virtual void AbstractSorting::sort (ElementVector & ev) [pure virtual]

Método que executa a ordenação dos elementos.

Implemented in BubbleSort, BubbleSort2, GnomeSort, ShakerSort, CombSort, InsertionSort, Selection-Sort, QuickPivotCentral, QuickPivotPeripheral, MergeSort, ShellSort, HeapSort, and InternalQuickSort.

Here is the caller graph for this function:

AbstractSorting::sort ExecuteSort main

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 13: Documentation - LibrarySorting

10 Class Documentation

4.1.4 Member Data Documentation

4.1.4.1 long double AbstractSorting::_numero_de_comparacoes [protected]

Atributo que irá armazenar o número de comparações realizadas.

Definition at line 37 of file SortingAlgorithms.h.

4.1.4.2 long double AbstractSorting::_numero_de_iteracoes [protected]

Atributo que irá armazenar o numero de iterações realizadas em cada algoritmo contado como operação demaior relevância a comparação e a possivel troca de valor entre duas posições que armazenam o valor deum determinado elemento.

Definition at line 26 of file SortingAlgorithms.h.

4.1.4.3 long double AbstractSorting::_numero_de_trocas [protected]

Atributo que irá armazenar para alguns algoritmos o número efetivo de trocas realizadas necessárias para aordenação da lista de elementos

Definition at line 32 of file SortingAlgorithms.h.

The documentation for this class was generated from the following files:

• SortingAlgorithms.h• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 14: Documentation - LibrarySorting

4.2 BubbleSort Class Reference 11

4.2 BubbleSort Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for BubbleSort:

BubbleSort

+ BubbleSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 15: Documentation - LibrarySorting

12 Class Documentation

Collaboration diagram for BubbleSort:

BubbleSort

+ BubbleSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Public Member Functions

• BubbleSort ()

• void sort (ElementVector &ev)

4.2.1 Detailed Description

Método da ordenação em bolha ou método bubble sort. Esse primeiro método é da ordem quadrática e nãoconstitui um algoritmo ótimo para ordenação, porém sua complexidade de implementação é muita baixa(trivial) em relação a outros algoritmos da mesma classe tal como o quicksort.

Definition at line 88 of file SortingAlgorithms.h.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 16: Documentation - LibrarySorting

4.2 BubbleSort Class Reference 13

4.2.2 Constructor & Destructor Documentation

4.2.2.1 BubbleSort::BubbleSort () [inline]

Contructor

Definition at line 94 of file SortingAlgorithms.h.

00094 :AbstractSorting(){};

4.2.3 Member Function Documentation

4.2.3.1 void BubbleSort::sort (ElementVector & ev) [virtual]

Método que executa a ordenação dos elementos.

Método da ordenação em bolha ou bubblesort. Esse primeiro método é da ordem quadrática e não constituium algoritmo ótimo para ordenação, porém sua complexidade de implementação é muita baixa (trivial) emrelação a outros algoritmos da mesma classe tal como o quicksort.

Implements AbstractSorting.

Definition at line 43 of file SortingAlgorithms.cxx.

00044 {00045 //std::cout << "Bubble..." << std::endl;00046 register unsigned int i,j;0004700048 //executa loopings para varrer a lista de números00049 for (i = 1; i < ev.size(); ++i)00050 {00051 for(j = ev.size()-1; j >= i; --j)00052 {00053 //executa troca caso encontre elementos desordenados00054 if ( ev[j-1] > ev[j] )00055 {00056 ev.swap(j-1,j);00057 _numero_de_trocas++;00058 }00059 _numero_de_comparacoes++;00060 _numero_de_iteracoes++;00061 }00062 }00063 }

Here is the call graph for this function:

BubbleSort::sort

ElementVector::size

ElementVector::swap

The documentation for this class was generated from the following files:

• SortingAlgorithms.h• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 17: Documentation - LibrarySorting

14 Class Documentation

4.3 BubbleSort2 Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for BubbleSort2:

BubbleSort2

+ BubbleSort2()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 18: Documentation - LibrarySorting

4.3 BubbleSort2 Class Reference 15

Collaboration diagram for BubbleSort2:

BubbleSort2

+ BubbleSort2()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Public Member Functions

• BubbleSort2 ()

• void sort (ElementVector &ev)

4.3.1 Detailed Description

Método da ordenação em bolha com alguma melhora em relação ao número de iterações e trocas. Casonão haja nenhuma troca o algoritmo não executa todas as iterações necessarias. Caso hajam muitas trocasa serem feitas o número de iterações irá superar o convencional estipulado pelo algoritmo BubbleSortconvencional.

Definition at line 109 of file SortingAlgorithms.h.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 19: Documentation - LibrarySorting

16 Class Documentation

4.3.2 Constructor & Destructor Documentation

4.3.2.1 BubbleSort2::BubbleSort2 () [inline]

Contructor

Definition at line 115 of file SortingAlgorithms.h.

00115 :AbstractSorting(){};

4.3.3 Member Function Documentation

4.3.3.1 void BubbleSort2::sort (ElementVector & ev) [virtual]

Método que executa a ordenação dos elementos.

Método da ordenação em bolha com alguma melhora em relação ao número de iterações e trocas. Casonão haja nenhuma troca o algoritmo não executa todas as iterações necessarias. Caso hajam muitas trocasa serem feitas o número de iterações irá superar o convencional estipulado pelo algoritmo BubbleSortconvencional.

Implements AbstractSorting.

Definition at line 72 of file SortingAlgorithms.cxx.

00073 {00074 bool houvetroca = false;00075 register unsigned int index = 0;00076 register unsigned int size_vector = ev.size();0007700078 while ((!houvetroca) && (index < size_vector - 1))00079 {00080 index = 0;00081 while(index < size_vector - 1)00082 {0008300084 //Verifica o número de comparações realizadas00085 _numero_de_comparacoes++;0008600087 //Verifica se algum elemento deve sofrer inversão00088 if (ev[index] > ev[index + 1])00089 {00090 ev.swap(index + 1,index);00091 houvetroca = true;00092 _numero_de_trocas++;00093 }0009400095 //Caso haja troca retorna o indice para o começo da lista00096 if(houvetroca) { index = 0; houvetroca = false; }00097 else { ++index;}00098 _numero_de_iteracoes++;00099 }00100 }00101 }

Here is the call graph for this function:

BubbleSort2::sort

ElementVector::size

ElementVector::swap

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 20: Documentation - LibrarySorting

4.3 BubbleSort2 Class Reference 17

The documentation for this class was generated from the following files:

• SortingAlgorithms.h• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 21: Documentation - LibrarySorting

18 Class Documentation

4.4 CombSort Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for CombSort:

CombSort

+ CombSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 22: Documentation - LibrarySorting

4.4 CombSort Class Reference 19

Collaboration diagram for CombSort:

CombSort

+ CombSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Public Member Functions

• CombSort ()• void sort (ElementVector &ev)

4.4.1 Detailed Description

Método que repetidamente reordena diferentes pares de itens, separados por um salto, que é calculado acada passagem, semelhante ao Bubble Sort, porém mais eficiente. O CombSort é um algoritmo relativa-mente simplista orinalmente criado por Wlodek Dobosiewicz em 1980, mais tarde redescoberto e popu-larizado por Stephen Lacey e Richard Box com um artigo na Byte Magazine [artigo publicado em abrilem 1991]. A idéia básica é a eliminação das ’Turtles’, ou valores pequenos perto do final da lista, já queno bubble sort estes valores pequenos retardam tremendamente a triagem e ordenação quando deslocadospara baixo[ou começo da lista]. ’Rabbits’, grandes valores em torno do início da lista, não representam umproblema no bubble sort. A maioria dos autores interpretam esse algoritmo como uma variante do ShellSort, só que usando um núcleo baseado em trocas [bubble] ao invés de inserções como o próprio Shell Sort.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 23: Documentation - LibrarySorting

20 Class Documentation

Definition at line 180 of file SortingAlgorithms.h.

4.4.2 Constructor & Destructor Documentation

4.4.2.1 CombSort::CombSort () [inline]

Contructor

Definition at line 186 of file SortingAlgorithms.h.

00186 :AbstractSorting(){};

4.4.3 Member Function Documentation

4.4.3.1 void CombSort::sort (ElementVector & ev) [virtual]

Método que executa a ordenação dos elementos.

Método que repetidamente reordena diferentes pares de itens, separados por um salto, que é calculado acada passagem, semelhante ao Bubble Sort, porém mais eficiente. O CombSort é um algoritmo relativa-mente simplista orinalmente criado por Wlodek Dobosiewicz em 1980, mais tarde redescoberto e popu-larizado por Stephen Lacey e Richard Box com um artigo na Byte Magazine [artigo publicado em abrilem 1991]. A idéia básica é a eliminação das ’Turtles’, ou valores pequenos perto do final da lista, já queno bubble sort estes valores pequenos retardam tremendamente a triagem e ordenação quando deslocadospara baixo[ou começo da lista]. ’Rabbits’, grandes valores em torno do início da lista, não representam umproblema no bubble sort. A maioria dos autores interpretam esse algoritmo como uma variante do ShellSort, só que usando um núcleo baseado em trocas [bubble] ao invés de inserções como o próprio Shell Sort.

Implements AbstractSorting.

Definition at line 556 of file SortingAlgorithms.cxx.

00557 {00558 //Variáveis de controle do tamanho do gap/salto/intervalo e troca de elementos00559 int gap = (int)ev.size();00560 int size_vector = (int)ev.size();00561 bool swapped = true;0056200563 //Verifica se o gap é maior que um ou se ainda está ocorrendo trocas00564 while (gap > 1 || swapped)00565 {00566 //Calculo do gap/salto/intervalo de aferição ou comparação dos elementos00567 if (gap > 1) { gap = (int) (gap / 1.3); }0056800569 //Variaveis de controle00570 int i = 0;00571 swapped = false;0057200573 //Looping onde ocorrerá verificações e trocas00574 while (i + gap < size_vector)00575 {00576 _numero_de_iteracoes++;00577 _numero_de_comparacoes++;00578 if (ev[i] > ev[i + gap])00579 {00580 _numero_de_trocas++;00581 ev.swap(i, i+gap);00582 swapped = true;00583 }

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 24: Documentation - LibrarySorting

4.4 CombSort Class Reference 21

00584 i++;00585 }00586 }00587 }

Here is the call graph for this function:

CombSort::sort

ElementVector::size

ElementVector::swap

The documentation for this class was generated from the following files:

• SortingAlgorithms.h• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 25: Documentation - LibrarySorting

22 Class Documentation

4.5 Element Class Reference

#include <Element.h>

Public Member Functions

• Element (long double value=0.0)• void value (long double Value)• long double value (void)• bool operator> (Element &e)• bool operator< (Element &e)• bool operator<= (Element &e)• virtual ∼Element ()

4.5.1 Detailed Description

Classe para armazenamento das caracteristicas de um determinado elemento

Definition at line 18 of file Element.h.

4.5.2 Constructor & Destructor Documentation

4.5.2.1 Element::Element (long double value = 0.0) [inline]

Método construtor da classe.

Definition at line 30 of file Element.h.

00030 {_value = value;};

Here is the call graph for this function:

Element::Element Element::value

4.5.2.2 virtual Element::∼Element () [inline, virtual]

Método destrutor. Responsável por liberar todos os recursos alocados pela classe.

Definition at line 61 of file Element.h.

00061 {};

4.5.3 Member Function Documentation

4.5.3.1 bool Element::operator< (Element & e) [inline]

Sobrecarga do operador < para simplificação da comparação de valores.

Definition at line 50 of file Element.h.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 26: Documentation - LibrarySorting

4.5 Element Class Reference 23

00050 { return (this->value() < e.value()); };

Here is the call graph for this function:

Element::operator< Element::value

4.5.3.2 bool Element::operator<= (Element & e) [inline]

Sobrecarga do operador <= para simplificação da comparação de valores.

Definition at line 55 of file Element.h.

00055 { return (this->value() <= e.value()); };

Here is the call graph for this function:

Element::operator<= Element::value

4.5.3.3 bool Element::operator> (Element & e) [inline]

Sobrecarga do operador > para simplificação da comparação de valores.

Definition at line 45 of file Element.h.

00045 { return (this->value() > e.value()); };

Here is the call graph for this function:

Element::operator> Element::value

4.5.3.4 long double Element::value (void) [inline]

Método que retorna o valor contido no atributo value.

Definition at line 40 of file Element.h.

00040 { return _value; };

Here is the caller graph for this function:

Element::value

Element::Element

Element::operator<

Element::operator<=

Element::operator>

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 27: Documentation - LibrarySorting

24 Class Documentation

4.5.3.5 void Element::value (long double Value) [inline]

Método que atribui um valor ao atributo value.

Definition at line 35 of file Element.h.

00035 { _value = Value; };

Here is the caller graph for this function:

Element::value

main

ElementVector::maxValue

ElementVector::minValue

Element::operator<

Element::operator<=

Element::operator>

ElementVector::absMaxValue

The documentation for this class was generated from the following file:

• Element.h

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 28: Documentation - LibrarySorting

4.6 ElementVector Class Reference 25

4.6 ElementVector Class Reference

#include <Element.h>

Public Member Functions

• ElementVector (void)• long double maxValue (void)• long double minValue (void)• long double absMaxValue (void)• bool isEmpty (void)• void resize (unsigned int new_size)• void sort (void)• unsigned int size (void)• Element at (unsigned int index)• Element & operator[ ] (unsigned int index)• void push_back (Element e)• void add (Element e)• void swap (unsigned int position_a, unsigned int position_b)• void clear (void)• virtual ∼ElementVector ()

4.6.1 Detailed Description

Classe para armazenamento de uma lista de elementos

Definition at line 76 of file Element.h.

4.6.2 Constructor & Destructor Documentation

4.6.2.1 ElementVector::ElementVector (void) [inline]

Método construtor da classe.

Definition at line 88 of file Element.h.

00088 {};

4.6.2.2 virtual ElementVector::∼ElementVector () [inline, virtual]

Método destrutor. Responsável por liberar todos os recursos alocados pela classe.

Definition at line 163 of file Element.h.

00163 { clear(); }

Here is the call graph for this function:

ElementVector::~ElementVector ElementVector::clear

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 29: Documentation - LibrarySorting

26 Class Documentation

4.6.3 Member Function Documentation

4.6.3.1 long double ElementVector::absMaxValue (void)

Método que retorna o maior valor absoluto contido na lista.

Definition at line 54 of file Element.cxx.

00055 {00056 return (fabsl(maxValue()) > fabsl(minValue()))?(maxValue()):(fabsl(minValue()))

;00057 }

Here is the call graph for this function:

ElementVector::absMaxValue

ElementVector::maxValue

ElementVector::minValue

ElementVector::at

Element::value

4.6.3.2 void ElementVector::add (Element e) [inline]

Método que insere elementos na lista

Definition at line 146 of file Element.h.

00146 { this->push_back(e); }

Here is the call graph for this function:

ElementVector::add ElementVector::push_back

Here is the caller graph for this function:

ElementVector::add main

4.6.3.3 Element ElementVector::at (unsigned int index) [inline]

Método que retorna o elemento de uma determinada posição

Definition at line 128 of file Element.h.

00128 { return _list.at(index); };

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 30: Documentation - LibrarySorting

4.6 ElementVector Class Reference 27

Here is the caller graph for this function:

ElementVector::at

main

ElementVector::maxValue

ElementVector::minValue

ElementVector::absMaxValue

4.6.3.4 void ElementVector::clear (void) [inline]

Método que executa limpeza da lista de elementos

Definition at line 157 of file Element.h.

00157 { _list.clear(); }

Here is the caller graph for this function:

ElementVector::clear

MergeSort::Merges

ElementVector::~ElementVector

MergeSort::MergeMethod MergeSort::sort

4.6.3.5 bool ElementVector::isEmpty (void) [inline]

Método que verifica se a alista está vazia

Definition at line 108 of file Element.h.

00108 { return _list.empty(); };

4.6.3.6 long double ElementVector::maxValue (void)

Método que retorna o maior valor existente na lista de elementos

Definition at line 13 of file Element.cxx.

00014 {00015 //Verificando se a lista foi preenchida ...00016 if (_list.size() == 0 ) return 0;0001700018 //Resgatando o primeiro elemento da lista para verificação do maior elemento00019 long double maximo = at(0).value();0002000021 //Looping para verificação do maior elemento00022 for (unsigned int index = 1; index < _list.size(); index++)00023 {00024 if (maximo < at(index).value()) maximo = at(index).value();00025 }0002600027 //Retornando o maior valor da lista00028 return maximo;00029 }

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 31: Documentation - LibrarySorting

28 Class Documentation

Here is the call graph for this function:

ElementVector::maxValue

ElementVector::at

Element::value

Here is the caller graph for this function:

ElementVector::maxValue ElementVector::absMaxValue

4.6.3.7 long double ElementVector::minValue (void)

Método que retorna o menor valor existente na lista de elementos

Definition at line 33 of file Element.cxx.

00034 {00035 //Verificando se a lista foi preenchida ...00036 if (_list.size() == 0 ) return 0;0003700038 //Resgatando o primeiro elemento da lista para verificação do maior elemento00039 long double minimo = at(0).value();0004000041 //Looping para verificação do maior elemento00042 for (unsigned int index = 1; index < _list.size(); index++)00043 {00044 if (minimo > at(index).value()) minimo = at(index).value();00045 }0004600047 //Retornando o maior valor da lista00048 return minimo;00049 }

Here is the call graph for this function:

ElementVector::minValue

ElementVector::at

Element::value

Here is the caller graph for this function:

ElementVector::minValue ElementVector::absMaxValue

4.6.3.8 Element& ElementVector::operator[ ] (unsigned int index) [inline]

Sobrecarga do operador [] para simplificar o acesso a um determinado elemento. Lembrando que esseoperador devolve uma referência, o que faz que acessemos diretamente o valor do objeto, além disso nãoexecutamos verificação de limites com esse operador, isso fica a cargo do programador.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 32: Documentation - LibrarySorting

4.6 ElementVector Class Reference 29

Definition at line 136 of file Element.h.

00136 { return _list[index]; };

4.6.3.9 void ElementVector::push_back (Element e) [inline]

Método que insere elementos na lista

Definition at line 141 of file Element.h.

00141 { _list.push_back(e); }

Here is the caller graph for this function:

ElementVector::push_back ElementVector::add main

4.6.3.10 void ElementVector::resize (unsigned int new_size) [inline]

Método que executa um resize na lista de elementos

Definition at line 113 of file Element.h.

00113 { _list.resize(new_size); };

Here is the caller graph for this function:

ElementVector::resize MergeSort::Merges MergeSort::MergeMethod MergeSort::sort

4.6.3.11 unsigned int ElementVector::size (void) [inline]

Método que retorna o tamanho da lista de elementos

Definition at line 123 of file Element.h.

00123 { return _list.size(); }

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 33: Documentation - LibrarySorting

30 Class Documentation

Here is the caller graph for this function:

ElementVector::size

main

CombSort::sort

ShakerSort::sort

GnomeSort::sort

HeapSort::sort

ShellSort::sort

MergeSort::sort

QuickPivotPeripheral::sort

QuickPivotCentral::sort

SelectionSort::sort

InsertionSort::sort

BubbleSort2::sort

BubbleSort::sort

4.6.3.12 void ElementVector::sort (void) [inline]

Método que utiliza o algoritmo de ordenação quick sort fornecido pela STL

Definition at line 118 of file Element.h.

00118 { std::sort(_list.begin(), _list.end(), PredicateSort()); };

Here is the caller graph for this function:

ElementVector::sort InternalQuickSort::sort

4.6.3.13 void ElementVector::swap (unsigned int position_a, unsigned int position_b)

Método que executa a troca entre dois valores de uma determinada posição dentro da lista de elementos.

Definition at line 63 of file Element.cxx.

00064 {00065 //Executa a troca dos valores00066 long double temp = _list[position_a].value();00067 _list[position_a].value( _list[position_b].value() );00068 _list[position_b].value(temp);00069 }

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 34: Documentation - LibrarySorting

4.6 ElementVector Class Reference 31

Here is the caller graph for this function:

ElementVector::swap

QuickPivotPeripheral::Partition

CombSort::sort

ShakerSort::sort

GnomeSort::sort

SelectionSort::sort

BubbleSort2::sort

BubbleSort::sort

QuickPivotPeripheral::QSort QuickPivotPeripheral::sort

The documentation for this class was generated from the following files:

• Element.h• Element.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 35: Documentation - LibrarySorting

32 Class Documentation

4.7 GnomeSort Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for GnomeSort:

GnomeSort

+ GnomeSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 36: Documentation - LibrarySorting

4.7 GnomeSort Class Reference 33

Collaboration diagram for GnomeSort:

GnomeSort

+ GnomeSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Public Member Functions

• GnomeSort ()

• void sort (ElementVector &ev)

4.7.1 Detailed Description

Método similiar ao Insertion sort com a diferença que o GnomeSort leva um elemento para sua posiçãocorreta, com uma seqüencia grande de trocas assim como o Bubble sort. O algoritmo percorre o vetorcomparando seus elementos dois a dois, assim que ele encontra um elemento que está na posição incorreta,ou seja, um número maior antes de um menor, ele troca a posição dos elementos, e volta com este elementoaté que encontre o seu respectivo lugar.

Definition at line 132 of file SortingAlgorithms.h.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 37: Documentation - LibrarySorting

34 Class Documentation

4.7.2 Constructor & Destructor Documentation

4.7.2.1 GnomeSort::GnomeSort () [inline]

Contructor

Definition at line 138 of file SortingAlgorithms.h.

00138 :AbstractSorting(){};

4.7.3 Member Function Documentation

4.7.3.1 void GnomeSort::sort (ElementVector & ev) [virtual]

Método que executa a ordenação dos elementos.

Método similiar ao Insertion sort com a diferença que o GnomeSort leva um elemento para sua posiçãocorreta, com uma seqüencia grande de trocas assim como o Bubble sort. O algoritmo percorre o vetorcomparando seus elementos dois a dois, assim que ele encontra um elemento que está na posição incorreta,ou seja, um número maior antes de um menor, ele troca a posição dos elementos, e volta com este elementoaté que encontre o seu respectivo lugar.

Implements AbstractSorting.

Definition at line 463 of file SortingAlgorithms.cxx.

00464 {00465 //Controlador de indice de posicionamento00466 unsigned int index = 1;0046700468 //looping que executa as ordenações00469 while( index < ev.size() )00470 {00471 //Sempre executa uma comparação antes de modificar o índice00472 _numero_de_comparacoes++;00473 _numero_de_iteracoes++;00474 if((index == 0) || ( ev[index-1] <= ev[index] ))00475 {00476 index++;00477 }00478 else00479 {00480 _numero_de_trocas++;00481 ev.swap( index - 1, index );00482 --index;00483 }00484 }00485 }

Here is the call graph for this function:

GnomeSort::sort

ElementVector::size

ElementVector::swap

The documentation for this class was generated from the following files:

• SortingAlgorithms.h

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 38: Documentation - LibrarySorting

4.7 GnomeSort Class Reference 35

• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 39: Documentation - LibrarySorting

36 Class Documentation

4.8 HeapSort Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for HeapSort:

HeapSort

+ HeapSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 40: Documentation - LibrarySorting

4.8 HeapSort Class Reference 37

Collaboration diagram for HeapSort:

HeapSort

+ HeapSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Public Member Functions

• HeapSort ()• void sort (ElementVector &ev)

4.8.1 Detailed Description

O algoritmo heapsort é um algoritmo de ordenação generalista, e faz parte da família de algoritmos deordenação por seleção. Tem um desempenho em tempo de execução muito bom em conjuntos ordenadosaleatoriamente, tem um uso de memória bem comportado e o seu desempenho em pior cenário é pratica-mente igual ao desempenho em cenário médio. Alguns algoritmos de ordenação rápidos têm desempenhosespectacularmente ruins no pior cenário, quer em tempo de execução, quer no uso da memória. O Heapsorttrabalha no lugar e o tempo de execução em pior cenário para ordenar n elementos é de O (n lg n). Paravalores de n, razoavelmente grande, o termo lg n é quase constante, de modo que o tempo de ordenação équase linear com o número de itens a ordenar.

Definition at line 367 of file SortingAlgorithms.h.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 41: Documentation - LibrarySorting

38 Class Documentation

4.8.2 Constructor & Destructor Documentation

4.8.2.1 HeapSort::HeapSort () [inline]

Contructor

Definition at line 373 of file SortingAlgorithms.h.

00373 :AbstractSorting(){};

4.8.3 Member Function Documentation

4.8.3.1 void HeapSort::sort (ElementVector & ev) [virtual]

Método que executa a ordenação dos elementos.

O algoritmo heapsort é um algoritmo de ordenação generalista, e faz parte da família de algoritmos deordenação por seleção. Tem um desempenho em tempo de execução muito bom em conjuntos ordenadosaleatoriamente, tem um uso de memória bem comportado e o seu desempenho em pior cenário é pratica-mente igual ao desempenho em cenário médio. Alguns algoritmos de ordenação rápidos têm desempenhosespectacularmente ruins no pior cenário, quer em tempo de execução, quer no uso da memória. O Heapsorttrabalha no lugar e o tempo de execução em pior cenário para ordenar n elementos é de O (n lg n). Paravalores de n, razoavelmente grande, o termo lg n é quase constante, de modo que o tempo de ordenação équase linear com o número de itens a ordenar.

Implements AbstractSorting.

Definition at line 393 of file SortingAlgorithms.cxx.

00394 {00395 int i = ev.size()/2, n = ev.size(), pai, filho;00396 Element t;0039700398 for (;;)00399 {00400 if (i > 0)00401 {00402 i--;00403 t = ev[i];00404 }00405 else00406 {00407 n--;00408 if (n == 0) return;00409 t = ev[n];00410 ev[n] = ev[0];00411 }0041200413 pai = i;00414 filho = i*2 + 1;0041500416 while (filho < n)00417 {00418 if ((filho + 1 < n) && (ev[filho + 1] > ev[filho]))00419 {00420 filho++;00421 _numero_de_comparacoes++;00422 }0042300424 if (ev[filho] > t)00425 {

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 42: Documentation - LibrarySorting

4.8 HeapSort Class Reference 39

00426 ev[pai] = ev[filho];00427 pai = filho;00428 filho = pai*2 + 1;0042900430 _numero_de_comparacoes++;00431 _numero_de_trocas++;00432 }00433 else break;0043400435 _numero_de_iteracoes++;00436 }0043700438 ev[pai] = t;00439 //_numero_de_trocas++;00440 _numero_de_iteracoes++;00441 }00442 }

Here is the call graph for this function:

HeapSort::sort ElementVector::size

The documentation for this class was generated from the following files:

• SortingAlgorithms.h• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 43: Documentation - LibrarySorting

40 Class Documentation

4.9 InsertionSort Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for InsertionSort:

InsertionSort

+ InsertionSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 44: Documentation - LibrarySorting

4.9 InsertionSort Class Reference 41

Collaboration diagram for InsertionSort:

InsertionSort

+ InsertionSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Public Member Functions

• InsertionSort ()• void sort (ElementVector &ev)

4.9.1 Detailed Description

Método da ordenação por inserção que também possui complexidade quadrática porém em média se com-porta melhor que a ordenação pelo método bolha.

Definition at line 198 of file SortingAlgorithms.h.

4.9.2 Constructor & Destructor Documentation

4.9.2.1 InsertionSort::InsertionSort () [inline]

Contructor

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 45: Documentation - LibrarySorting

42 Class Documentation

Definition at line 204 of file SortingAlgorithms.h.

00204 :AbstractSorting(){};

4.9.3 Member Function Documentation

4.9.3.1 void InsertionSort::sort (ElementVector & ev) [virtual]

Método que executa a ordenação dos elementos.

Método da ordenação por inserção que também possui complexidade quadrática porém em média se com-porta melhor que a ordenação pelo método bolha.

Implements AbstractSorting.

Definition at line 107 of file SortingAlgorithms.cxx.

00108 {00109 Element temp;00110 int index;00111 unsigned int j, size_vector = ev.size();0011200113 for(j = 1; j < size_vector; j++)00114 {00115 temp = ev[j];0011600117 //O algoritmo faz pelo menos uma comparação antes de entrar no looping e uma00118 //iteração pois se as condições do cabeçalho condicional do próximo laço não00119 //forem aceitas o looping[for] não será executado.00120 _numero_de_iteracoes++;00121 _numero_de_comparacoes++;0012200123 //O restante das comparações são feitas pelo cabeçalho condicional do laço00124 for(index = j-1; index >= 0 && ev[index] > temp; index--)00125 {00126 ev[index + 1] = ev[index];00127 _numero_de_iteracoes++;00128 _numero_de_trocas++;00129 _numero_de_comparacoes++;00130 }0013100132 //Necessáriamente isso é apenas uma reatribuição quando a lista já se00133 //encontra ordenada, por isso comentamos o incremento do número de trocas00134 //_numero_de_trocas++;00135 ev[index + 1] = temp;00136 }00137 }

Here is the call graph for this function:

InsertionSort::sort ElementVector::size

The documentation for this class was generated from the following files:

• SortingAlgorithms.h• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 46: Documentation - LibrarySorting

4.10 InternalQuickSort Class Reference 43

4.10 InternalQuickSort Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for InternalQuickSort:

InternalQuickSort

+ InternalQuickSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 47: Documentation - LibrarySorting

44 Class Documentation

Collaboration diagram for InternalQuickSort:

InternalQuickSort

+ InternalQuickSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Public Member Functions

• InternalQuickSort ()• void sort (ElementVector &ev)

4.10.1 Detailed Description

Método que utiliza o algoritmo quiscksort implementado pela STL. Por isso o número de comparações,iterações e trocas não poderá ser fornecido com precisão

Definition at line 385 of file SortingAlgorithms.h.

4.10.2 Constructor & Destructor Documentation

4.10.2.1 InternalQuickSort::InternalQuickSort () [inline]

Contructor

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 48: Documentation - LibrarySorting

4.10 InternalQuickSort Class Reference 45

Definition at line 391 of file SortingAlgorithms.h.

00391 :AbstractSorting(){};

4.10.3 Member Function Documentation

4.10.3.1 void InternalQuickSort::sort (ElementVector & ev) [virtual]

Método que executa a ordenação dos elementos.

Método que utiliza o algoritmo quiscksort implementado pela STL. Por isso o número de comparações,iterações e trocas não poderá ser fornecido com precisão

Implements AbstractSorting.

Definition at line 448 of file SortingAlgorithms.cxx.

00449 {00450 //Executa o método de ordenação fornecido pela STL baseado no quicksort00451 ev.sort();00452 }

Here is the call graph for this function:

InternalQuickSort::sort ElementVector::sort

The documentation for this class was generated from the following files:

• SortingAlgorithms.h• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 49: Documentation - LibrarySorting

46 Class Documentation

4.11 MergeSort Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for MergeSort:

MergeSort

+ MergeSort()+ sort()+ MergeMethod()+ Merges()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 50: Documentation - LibrarySorting

4.11 MergeSort Class Reference 47

Collaboration diagram for MergeSort:

MergeSort

+ MergeSort()+ sort()+ MergeMethod()+ Merges()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Public Member Functions

• MergeSort ()

• void sort (ElementVector &ev)

• void MergeMethod (ElementVector &ev, int BeginList, int EndList)

• void Merges (ElementVector &ev, int BeginList, int Middle, int EndList)

4.11.1 Detailed Description

Método de Ordenação Merge Sort

Definition at line 298 of file SortingAlgorithms.h.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 51: Documentation - LibrarySorting

48 Class Documentation

4.11.2 Constructor & Destructor Documentation

4.11.2.1 MergeSort::MergeSort () [inline]

Contructor

Definition at line 304 of file SortingAlgorithms.h.

00304 :AbstractSorting(){};

4.11.3 Member Function Documentation

4.11.3.1 void MergeSort::MergeMethod (ElementVector & ev, int BeginList, int EndList)

Método merge sort, ou ordenação por intercalação, é um exemplo de algoritmo de ordenação do tipodividir-para-conquistar. Sua idéia básica é que é muito fácil criar uma sequência ordenada a partir de duasoutras também ordenadas. Para isso, ele divide a sequência original em pares de dados, ordena-as; depoisas agrupa em sequências de quatro elementos, e assim por diante, até ter toda a sequência dividida emapenas duas partes. O método MergeSort rearranja o vetor v[BeginList..EndList-1] em ordem crescente.Cuidado ao usar esse método, o final da lista compreende todo o seu tamanho, logo o mesmo deve serchamado da seguinte forma : MergeSort(MinhaLista, 0, MinhaLista.size())

Definition at line 282 of file SortingAlgorithms.cxx.

00283 {00284 if (BeginList < EndList -1)00285 {00286 int middle = (BeginList + EndList)/2;00287 MergeMethod(ev, BeginList, middle);00288 MergeMethod(ev, middle, EndList);00289 Merges(ev, BeginList, middle, EndList);00290 }00291 }

Here is the call graph for this function:

MergeSort::MergeMethod MergeSort::Merges

ElementVector::clear

ElementVector::resize

Here is the caller graph for this function:

MergeSort::MergeMethod MergeSort::sort

4.11.3.2 void MergeSort::Merges (ElementVector & ev, int BeginList, int Middle, int EndList)

Método auxiliar ao MergeSort que executa a intercalação das listas. O método recebe vetores crescentesv[BeginList..Middle-1] e v[Middle..EndList-1] e rearranja v[BeginList..EndList-1] em ordem crescente.

Definition at line 298 of file SortingAlgorithms.cxx.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 52: Documentation - LibrarySorting

4.11 MergeSort Class Reference 49

00299 {00300 int i, j, k;00301 ElementVector w;0030200303 //Executa um resize na lista de elementos alocando o necessário para a00304 //intercalação dos elementos.00305 w.resize(EndList - BeginList);0030600307 //Estabelecendo os limites para a intercalação00308 i = BeginList; j = Middle; k = 0;0030900310 //Verifica quem deve ser intercalado00311 while( i < Middle && j < EndList)00312 {00313 if (ev[i] <= ev[j]) w[k++] = ev[i++];00314 else w[k++] = ev[j++];0031500316 //Executa analise de desempenho do algoritmo.00317 _numero_de_comparacoes++;00318 _numero_de_trocas++;00319 _numero_de_iteracoes++;00320 }0032100322 //Executa as intercalações finais.00323 while(i < Middle) { w[k++] = ev[i++]; _numero_de_iteracoes++; }00324 while(j < EndList) { w[k++] = ev[j++]; _numero_de_iteracoes++; }0032500326 //Copia o a lista auxiliar para a lista original00327 for( i = BeginList; i < EndList; ++i)00328 { ev[i] = w[i-BeginList]; _numero_de_iteracoes++; }0032900330 //Limpa a lista auxiliar ...00331 w.clear();00332 }

Here is the call graph for this function:

MergeSort::Merges

ElementVector::clear

ElementVector::resize

Here is the caller graph for this function:

MergeSort::Merges MergeSort::MergeMethod MergeSort::sort

4.11.3.3 void MergeSort::sort (ElementVector & ev) [virtual]

Método que executa a ordenação dos elementos.

Implements AbstractSorting.

Definition at line 269 of file SortingAlgorithms.cxx.

00269 { MergeMethod(ev, 0, ev.size()); };

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 53: Documentation - LibrarySorting

50 Class Documentation

Here is the call graph for this function:

MergeSort::sort

MergeSort::MergeMethod

ElementVector::size

MergeSort::Merges

ElementVector::clear

ElementVector::resize

The documentation for this class was generated from the following files:

• SortingAlgorithms.h• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 54: Documentation - LibrarySorting

4.12 PredicateSort Struct Reference 51

4.12 PredicateSort Struct Reference

#include <Element.h>

Public Member Functions

• bool operator() (Element a, Element b)

4.12.1 Detailed Description

Estrutura auxiliar usada como predicado para executar ordenação usando o quicksort interno da STL.

Definition at line 68 of file Element.h.

4.12.2 Member Function Documentation

4.12.2.1 bool PredicateSort::operator() (Element a, Element b) [inline]

Definition at line 70 of file Element.h.

00070 { return a < b; }

The documentation for this struct was generated from the following file:

• Element.h

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 55: Documentation - LibrarySorting

52 Class Documentation

4.13 QuickPivotCentral Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for QuickPivotCentral:

QuickPivotCentral

+ QuickPivotCentral()+ sort()+ QuickSort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 56: Documentation - LibrarySorting

4.13 QuickPivotCentral Class Reference 53

Collaboration diagram for QuickPivotCentral:

QuickPivotCentral

+ QuickPivotCentral()+ sort()+ QuickSort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Public Member Functions

• QuickPivotCentral ()

• void sort (ElementVector &ev)

• void QuickSort (ElementVector &ev, int BeginList, int EndList)

4.13.1 Detailed Description

Método de Ordenação QuickSort Nº 1 - Pivoteamento Central

Definition at line 233 of file SortingAlgorithms.h.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 57: Documentation - LibrarySorting

54 Class Documentation

4.13.2 Constructor & Destructor Documentation

4.13.2.1 QuickPivotCentral::QuickPivotCentral () [inline]

Contructor

Definition at line 239 of file SortingAlgorithms.h.

00239 :AbstractSorting(){};

4.13.3 Member Function Documentation

4.13.3.1 void QuickPivotCentral::QuickSort (ElementVector & ev, int BeginList, int EndList)

Método de Ordenação QuickSort é um método de ordenação muito rápido e eficiente, inventado por C.A.R.Hoare em 1960. O Quicksort é um algoritmo de ordenação não-estável que adota a estratégia de divisãoe conquista, podendo sofrer degeneração no melhor caso e caso médio [nlogn] para o pior caso [n∧2].Essa implementação pode ser encontrada no livro de Sedgewick. O método rearranja o vetor v[p..r], comp <= r+1, de modo que ele fique em ordem crescente.Esse método não se utiliza de um particionadorexplicito e o pivo de verificação sempre é dado por um elemento central. Cuidado ao usar esse método,o final da lista deve ser passado como size()-1, logo o mesmo deve ser chamado da seguinte forma :QuickSort(MinhaLista, 0, MinhaLista.size() - 1)

Método de Ordenação QuickSort é um método de ordenação muito rápido e eficiente, inventado por C.A.R.Hoare em 1960. O Quicksort é um algoritmo de ordenação não-estável que adota a estratégia de divisão econquista, podendo sofrer degeneração no melhor caso e caso médio [nlogn] para o pior caso [n∧2]. Essaimplementação pode ser encontrada no livro de Sedgewick. O método rearranja o vetor v[p..r], com p <=r+1, de modo que ele fique em ordem crescente. Esse método não se utiliza de um particionador explicitoe o pivô de verificação sempre é dado por um elemento central.

Definition at line 182 of file SortingAlgorithms.cxx.

00183 {00184 int i , j;00185 Element c, t;0018600187 if (BeginList < EndList)00188 {00189 c = ev[(BeginList + EndList) / 2];00190 i = BeginList; j = EndList;0019100192 while (i <= j)00193 {00194 while (ev[i] < c) { ++i; _numero_de_comparacoes++; _numero_de_iteracoes++;

}00195 while (c < ev[j]) { --j; _numero_de_comparacoes++; _numero_de_iteracoes++;

}0019600197 if (i <= j)00198 {00199 t = ev[i], ev[i] = ev[j], ev[j] = t;00200 ++i, --j;00201 _numero_de_trocas++;00202 }00203 _numero_de_iteracoes++;00204 }0020500206 //Segmento onde ocorre a chamada recursiva ao método00207 QuickSort(ev, BeginList, j);00208 QuickSort(ev, i, EndList);

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 58: Documentation - LibrarySorting

4.13 QuickPivotCentral Class Reference 55

00209 }00210 }

Here is the caller graph for this function:

QuickPivotCentral::QuickSort QuickPivotCentral::sort

4.13.3.2 void QuickPivotCentral::sort (ElementVector & ev) [virtual]

Método que executa a ordenação dos elementos.

Implements AbstractSorting.

Definition at line 170 of file SortingAlgorithms.cxx.

00170 { QuickSort(ev, 0, ev.size() - 1); };

Here is the call graph for this function:

QuickPivotCentral::sort

QuickPivotCentral::QuickSort

ElementVector::size

The documentation for this class was generated from the following files:

• SortingAlgorithms.h• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 59: Documentation - LibrarySorting

56 Class Documentation

4.14 QuickPivotPeripheral Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for QuickPivotPeripheral:

QuickPivotPeripheral

+ QuickPivotPeripheral()+ sort()+ QSort()+ Partition()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 60: Documentation - LibrarySorting

4.14 QuickPivotPeripheral Class Reference 57

Collaboration diagram for QuickPivotPeripheral:

QuickPivotPeripheral

+ QuickPivotPeripheral()+ sort()+ QSort()+ Partition()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Public Member Functions

• QuickPivotPeripheral ()

• void sort (ElementVector &ev)

• void QSort (ElementVector &ev, int left, int right)

• int Partition (ElementVector &ev, int left, int right)

4.14.1 Detailed Description

Método de Ordenação QuickSort Nº 2 - Pivoteamento Periférico

Definition at line 265 of file SortingAlgorithms.h.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 61: Documentation - LibrarySorting

58 Class Documentation

4.14.2 Constructor & Destructor Documentation

4.14.2.1 QuickPivotPeripheral::QuickPivotPeripheral () [inline]

Contructor

Definition at line 271 of file SortingAlgorithms.h.

00271 :AbstractSorting(){};

4.14.3 Member Function Documentation

4.14.3.1 int QuickPivotPeripheral::Partition (ElementVector & ev, int left, int right)

Método auxiliar ao QSort que executa particionamento da lista de elementos.

Definition at line 240 of file SortingAlgorithms.cxx.

00241 {00242 register int i, j;0024300244 i = left;0024500246 for (j = left + 1; j <= right; j++)00247 {00248 _numero_de_iteracoes++;00249 _numero_de_comparacoes++;00250 if (ev[j] < ev[left])00251 {00252 ++i;00253 ev.swap(i,j);00254 _numero_de_trocas++;00255 }00256 }0025700258 //O elemento do limite da partição é trocado com o pivô. Necessáriamente isso00259 //é apenas uma reatribuição quando a lista já se encontra ordenada. Por isso00260 //comentamos o incremento na variável de troca.00261 //_numero_de_trocas++;00262 ev.swap(left,i);00263 return i;00264 }

Here is the call graph for this function:

QuickPivotPeripheral::Partition ElementVector::swap

Here is the caller graph for this function:

QuickPivotPeripheral::Partition QuickPivotPeripheral::QSort QuickPivotPeripheral::sort

4.14.3.2 void QuickPivotPeripheral::QSort (ElementVector & ev, int left, int right)

Método de ordenação quick sort que utiliza uma função de particionamento da lista de elementos. Essemétodo utiliza um particionador explícito porém seu pivo de verificação não é um elemento central previa-

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 62: Documentation - LibrarySorting

4.14 QuickPivotPeripheral Class Reference 59

mente definido e sim os elementos que estam mais a direita de cada partição definida.Cuidado ao usar essemétodo, o final da lista deve ser passado como size()-1, logo o mesmo deve ser chamado da seguinte forma: QSort(MinhaLista, 0, MinhaLista.size() - 1)

Método de ordenação quick sort que utiliza uma função de particionamento da lista de elementos. Essemétodo utiliza um particionador explícito porém seu pivo de verificação não é um elemento central previ-amente definido e sim elementos que se encontram mais a esquerda de cada partição definida.

Definition at line 223 of file SortingAlgorithms.cxx.

00224 {00225 int new_right;0022600227 if (right > left)00228 {00229 new_right = Partition(ev, left, right);00230 QSort(ev,left, new_right - 1);00231 QSort(ev,new_right + 1,right);00232 }0023300234 return;00235 }

Here is the call graph for this function:

QuickPivotPeripheral::QSort QuickPivotPeripheral::Partition ElementVector::swap

Here is the caller graph for this function:

QuickPivotPeripheral::QSort QuickPivotPeripheral::sort

4.14.3.3 void QuickPivotPeripheral::sort (ElementVector & ev) [virtual]

Método que executa a ordenação dos elementos.

Implements AbstractSorting.

Definition at line 215 of file SortingAlgorithms.cxx.

00215 { QSort(ev, 0, ev.size() - 1); };

Here is the call graph for this function:

QuickPivotPeripheral::sort

QuickPivotPeripheral::QSort

ElementVector::size

QuickPivotPeripheral::Partition ElementVector::swap

The documentation for this class was generated from the following files:

• SortingAlgorithms.h• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 63: Documentation - LibrarySorting

60 Class Documentation

4.15 SelectionSort Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for SelectionSort:

SelectionSort

+ SelectionSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 64: Documentation - LibrarySorting

4.15 SelectionSort Class Reference 61

Collaboration diagram for SelectionSort:

SelectionSort

+ SelectionSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Public Member Functions

• SelectionSort ()• void sort (ElementVector &ev)

4.15.1 Detailed Description

Método da ordenação por seleção que também possui complexidade quadrática porém em média se com-porta melhor que a ordenação pelo método bolha.

Definition at line 216 of file SortingAlgorithms.h.

4.15.2 Constructor & Destructor Documentation

4.15.2.1 SelectionSort::SelectionSort () [inline]

Contructor

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 65: Documentation - LibrarySorting

62 Class Documentation

Definition at line 222 of file SortingAlgorithms.h.

00222 :AbstractSorting(){};

4.15.3 Member Function Documentation

4.15.3.1 void SelectionSort::sort (ElementVector & ev) [virtual]

Método que executa a ordenação dos elementos.

Método da ordenação por seleção que também possui complexidade quadrática porém em média se com-porta melhor que a ordenação pelo método bolha.

Implements AbstractSorting.

Definition at line 143 of file SortingAlgorithms.cxx.

00144 {00145 register unsigned int index,j,minimum;00146 register unsigned int size_vector = ev.size();0014700148 for(j = 0; j < size_vector - 1; ++j)00149 {00150 minimum = j;0015100152 //Procura pelo índice com o menor elemento00153 for(index = j+1; index < size_vector; ++index)00154 {00155 _numero_de_comparacoes++;00156 _numero_de_iteracoes++;00157 if (ev[index] < ev[minimum]) minimum = index;00158 }0015900160 //Quando acha o menor elemento executa a troca. Necessáriamente isso é apenas

00161 //uma reatribuição quando a lista já se encontra ordenada.00162 _numero_de_trocas++;00163 ev.swap(j,minimum);00164 }00165 }

Here is the call graph for this function:

SelectionSort::sort

ElementVector::size

ElementVector::swap

The documentation for this class was generated from the following files:

• SortingAlgorithms.h• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 66: Documentation - LibrarySorting

4.16 ShakerSort Class Reference 63

4.16 ShakerSort Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for ShakerSort:

ShakerSort

+ ShakerSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 67: Documentation - LibrarySorting

64 Class Documentation

Collaboration diagram for ShakerSort:

ShakerSort

+ ShakerSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Public Member Functions

• ShakerSort ()• void sort (ElementVector &ev)

4.16.1 Detailed Description

O Método de ordenação ShakerSort funciona como o Bubble Sort, mas de forma bidirecional e também éconhecido como Cocktail Sort, possuindo complexidade quadrática, ou seja O(n∧2).

Definition at line 151 of file SortingAlgorithms.h.

4.16.2 Constructor & Destructor Documentation

4.16.2.1 ShakerSort::ShakerSort () [inline]

Contructor

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 68: Documentation - LibrarySorting

4.16 ShakerSort Class Reference 65

Definition at line 157 of file SortingAlgorithms.h.

00157 :AbstractSorting(){};

4.16.3 Member Function Documentation

4.16.3.1 void ShakerSort::sort (ElementVector & ev) [virtual]

Método que executa a ordenação dos elementos.

O Método de ordenação ShakerSort funciona como o Bubble Sort, mas de forma bidirecional e também éconhecido como Cocktail Sort, possuindo complexidade quadrática, ou seja O(n∧2).

Implements AbstractSorting.

Definition at line 492 of file SortingAlgorithms.cxx.

00493 {00494 //Declaração e atribuição das variaveis de controle00495 int length, bottom, top, i; bool swapped = false;00496 length = ev.size(); bottom = 0; top = length - 1; swapped = false;0049700498 //Se não houver troca de posições ou o ponteiro que00499 //sobe ultrapassar o que desce, o vetor estará ordenado00500 while(swapped == 0 && bottom < top)00501 {00502 swapped = true;0050300504 //Este looping é a ida para a direita00505 for(i = bottom; i < top; i = i + 1)00506 {00507 //indo pra direita: testa se o próximo é maior00508 //indo pra direita: se o proximo é maior que o atual troca as posições00509 _numero_de_comparacoes++;00510 _numero_de_iteracoes++;00511 if(ev[i] > ev[i + 1])00512 {00513 ev.swap(i, i + 1);00514 swapped = false;00515 _numero_de_trocas++;00516 }00517 }0051800519 // Diminui o ‘top‘ porque o elemento com o maior valor00520 // já está na direita (atual posição top)00521 top = top - 1;0052200523 //Este looping é a ida para a esquerda00524 for(i = top; i > bottom; i = i - 1)00525 {00526 _numero_de_comparacoes++;00527 _numero_de_iteracoes++;00528 if(ev[i] < ev[i - 1])00529 {00530 ev.swap(i, i - 1);00531 swapped = false;00532 _numero_de_trocas++;00533 }00534 }0053500536 //Aumenta o ‘bottom‘ porque o menor valor já está na posição inicial00537 bottom = bottom + 1;00538 }00539 }

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 69: Documentation - LibrarySorting

66 Class Documentation

Here is the call graph for this function:

ShakerSort::sort

ElementVector::size

ElementVector::swap

The documentation for this class was generated from the following files:

• SortingAlgorithms.h• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 70: Documentation - LibrarySorting

4.17 ShellSort Class Reference 67

4.17 ShellSort Class Reference

#include <SortingAlgorithms.h>

Inheritance diagram for ShellSort:

ShellSort

+ ShellSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 71: Documentation - LibrarySorting

68 Class Documentation

Collaboration diagram for ShellSort:

ShellSort

+ ShellSort()+ sort()

AbstractSorting

# _numero_de_iteracoes# _numero_de_trocas# _numero_de_comparacoes

+ AbstractSorting()+ InitializeVariables()+ IterationsNumber()+ InversionsNumber()+ ComparisonsNumber()+ sort()+ ~AbstractSorting()

Public Member Functions

• ShellSort ()

• void sort (ElementVector &ev)

4.17.1 Detailed Description

Método Shell sort é o mais eficiente algoritmo de classificação dentre os de complexidade quadrática.Basicamente o algoritmo passa várias vezes pela lista dividindo o grupo maior em menores. Nos gruposmenores é aplicado o método da ordenação por inserção. Dependendo da escolha do tamanho do saltoo algoritmo pode apresentar complexidade O(n∧2), O(n∗(logn)∧2) ou até mesmo O(n∗(logn)). Porém omesmo não deixa de ser classificado como um algoritmo da ordem O(n∧2).

Definition at line 341 of file SortingAlgorithms.h.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 72: Documentation - LibrarySorting

4.17 ShellSort Class Reference 69

4.17.2 Constructor & Destructor Documentation

4.17.2.1 ShellSort::ShellSort () [inline]

Contructor

Definition at line 347 of file SortingAlgorithms.h.

00347 :AbstractSorting(){};

4.17.3 Member Function Documentation

4.17.3.1 void ShellSort::sort (ElementVector & ev) [virtual]

Método que executa a ordenação dos elementos.

Método Shell sort é o mais eficiente algoritmo de classificação dentre os de complexidade quadrática.Basicamente o algoritmo passa várias vezes pela lista dividindo o grupo maior em menores. Nos gruposmenores é aplicado o método da ordenação por inserção. Dependendo da escolha do tamanho do saltoo algoritmo pode apresentar complexidade O(n∧2), O(n∗(logn)∧2) ou até mesmo O(n∗(logn)). Porém omesmo não deixa de ser classificado como um algoritmo da ordem O(n∧2).

Implements AbstractSorting.

Definition at line 343 of file SortingAlgorithms.cxx.

00344 {00345 int h, size = ev.size();0034600347 for( h = 1; h < size; h = 3 * h + 1 );0034800349 do00350 {00351 //Tamanho do gap ou salto que sera dado de 3 em 3 dentro do compartimento...00352 h /= 3;0035300354 //Executando looping para verificação e ordenação ...00355 for( int i = h; i < size; ++i )00356 {00357 Element value = ev[i];00358 int j;0035900360 //O algoritmo faz pelo menos uma comparação antes de entrar no looping e um

a00361 //iteração pois se as condições do cabeçalho condicional do próximo laço nã

o00362 //forem aceitas o looping[for] não será executado.00363 _numero_de_iteracoes++;00364 _numero_de_comparacoes++;0036500366 for( j = i - h; j >= 0 && value < ev[j]; j -= h )00367 {00368 ev[j+h] = ev[j];00369 _numero_de_iteracoes++;00370 _numero_de_trocas++;00371 _numero_de_comparacoes++;00372 }0037300374 _numero_de_trocas++;00375 ev[j+h] = value;00376 }00377 }while( h > 1 );

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 73: Documentation - LibrarySorting

70 Class Documentation

0037800379 }

Here is the call graph for this function:

ShellSort::sort ElementVector::size

The documentation for this class was generated from the following files:

• SortingAlgorithms.h• SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 74: Documentation - LibrarySorting

Chapter 5

File Documentation

5.1 Element.cxx File Reference

#include "Element.h"

#include <vector>

#include <cmath>

#include <algorithm>

Include dependency graph for Element.cxx:

Element.cxx

vector cmath algorithm

This graph shows which files directly or indirectly include this file:

Element.cxx

Page 75: Documentation - LibrarySorting

72 File Documentation

5.2 Element.cxx

00001 /*00002 * _Element.cpp00003 *00004 * Created on: 25/10/200900005 * Author: Administrador00006 */0000700008 #include "Element.h"0000900013 long double ElementVector::maxValue(void)00014 {00015 //Verificando se a lista foi preenchida ...00016 if (_list.size() == 0 ) return 0;0001700018 //Resgatando o primeiro elemento da lista para verificação do maior elemento00019 long double maximo = at(0).value();0002000021 //Looping para verificação do maior elemento00022 for (unsigned int index = 1; index < _list.size(); index++)00023 {00024 if (maximo < at(index).value()) maximo = at(index).value();00025 }0002600027 //Retornando o maior valor da lista00028 return maximo;00029 }00033 long double ElementVector::minValue(void)00034 {00035 //Verificando se a lista foi preenchida ...00036 if (_list.size() == 0 ) return 0;0003700038 //Resgatando o primeiro elemento da lista para verificação do maior elemento00039 long double minimo = at(0).value();0004000041 //Looping para verificação do maior elemento00042 for (unsigned int index = 1; index < _list.size(); index++)00043 {00044 if (minimo > at(index).value()) minimo = at(index).value();00045 }0004600047 //Retornando o maior valor da lista00048 return minimo;00049 }0005000054 long double ElementVector::absMaxValue(void)00055 {00056 return (fabsl(maxValue()) > fabsl(minValue()))?(maxValue()):(fabsl(minValue()))

;00057 }0005800063 void ElementVector::swap(unsigned int position_a, unsigned int position_b)00064 {00065 //Executa a troca dos valores00066 long double temp = _list[position_a].value();00067 _list[position_a].value( _list[position_b].value() );00068 _list[position_b].value(temp);00069 }0007000071

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 76: Documentation - LibrarySorting

5.3 Element.h File Reference 73

5.3 Element.h File Reference

#include <vector>

#include <cmath>

#include <algorithm>

Include dependency graph for Element.h:

Element.h

vector cmath algorithm

This graph shows which files directly or indirectly include this file:

Element.h

SortingAlgorithms.cxx SortingAlgorithms.h

Sys-LibrarySorting.cpp

Classes

• class Element• struct PredicateSort• class ElementVector

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 77: Documentation - LibrarySorting

74 File Documentation

5.4 Element.h

00001 /*00002 * Element.h00003 *00004 * Created on: 25/10/200900005 * Author: Michel Alves dos Santos00006 */0000700008 #ifndef _ELEMENT_H_00009 #define _ELEMENT_H_0001000011 #include <vector>00012 #include <cmath>00013 #include <algorithm>0001400018 class Element00019 {00023 long double _value;0002400025 public :0002600030 Element(long double value = 0.0){_value = value;};0003100035 void value(long double Value) { _value = Value; };0003600040 long double value(void) { return _value; };0004100045 bool operator > (Element& e) { return (this->value() > e.value()); };0004600050 bool operator < (Element& e) { return (this->value() < e.value()); };0005100055 bool operator <= (Element& e) { return (this->value() <= e.value()); };0005600061 virtual ~Element() {};00062 };0006300068 struct PredicateSort00069 {00070 bool operator()(Element a, Element b) { return a < b; }00071 };0007200076 class ElementVector00077 {00081 std::vector<Element> _list;0008200083 public:0008400088 ElementVector(void){};0008900093 long double maxValue(void);0009400098 long double minValue(void);0009900103 long double absMaxValue(void);0010400108 bool isEmpty(void) { return _list.empty(); };0010900113 void resize(unsigned int new_size) { _list.resize(new_size); };0011400118 void sort(void) { std::sort(_list.begin(), _list.end(), PredicateSort()); };0011900123 unsigned int size(void) { return _list.size(); }0012400128 Element at(unsigned int index) { return _list.at(index); };0012900136 Element& operator [](unsigned int index) { return _list[index]; };

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 78: Documentation - LibrarySorting

5.4 Element.h 75

0013700141 void push_back(Element e) { _list.push_back(e); }0014200146 void add(Element e) { this->push_back(e); }0014700152 void swap(unsigned int position_a, unsigned int position_b);0015300157 void clear(void) { _list.clear(); }0015800163 virtual ~ElementVector(){ clear(); }00164 };0016500166 #endif /* _ELEMENT_H_ */

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 79: Documentation - LibrarySorting

76 File Documentation

5.5 SortingAlgorithms.cxx File Reference

#include "SortingAlgorithms.h"

#include "Element.h"

#include <iostream>

Include dependency graph for SortingAlgorithms.cxx:

SortingAlgorithms.cxx

Element.h iostream

vector cmath algorithm

This graph shows which files directly or indirectly include this file:

SortingAlgorithms.cxx

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 80: Documentation - LibrarySorting

5.6 SortingAlgorithms.cxx 77

5.6 SortingAlgorithms.cxx

00001 /*00002 * SortingAlgorithms.cpp00003 *00004 * Created on: 26/10/200900005 * Author: Administrador00006 */0000700008 #include "SortingAlgorithms.h"0000900010 //---------------------------------------------------------------------------00011 /* Classe base para uso do padrão strategy.*/00012 //---------------------------------------------------------------------------00016 AbstractSorting::AbstractSorting()00017 {00018 InitializeVariables();00019 }0002000026 void AbstractSorting::InitializeVariables(void)00027 {00028 _numero_de_iteracoes = 0;00029 _numero_de_trocas = 0;00030 _numero_de_comparacoes = 0;00031 }0003200033 //---------------------------------------------------------------------------00034 /* Classes de ordenação .*/00035 //---------------------------------------------------------------------------00043 void BubbleSort::sort(ElementVector & ev)00044 {00045 //std::cout << "Bubble..." << std::endl;00046 register unsigned int i,j;0004700048 //executa loopings para varrer a lista de números00049 for (i = 1; i < ev.size(); ++i)00050 {00051 for(j = ev.size()-1; j >= i; --j)00052 {00053 //executa troca caso encontre elementos desordenados00054 if ( ev[j-1] > ev[j] )00055 {00056 ev.swap(j-1,j);00057 _numero_de_trocas++;00058 }00059 _numero_de_comparacoes++;00060 _numero_de_iteracoes++;00061 }00062 }00063 }0006400072 void BubbleSort2::sort(ElementVector & ev)00073 {00074 bool houvetroca = false;00075 register unsigned int index = 0;00076 register unsigned int size_vector = ev.size();0007700078 while ((!houvetroca) && (index < size_vector - 1))00079 {00080 index = 0;00081 while(index < size_vector - 1)00082 {0008300084 //Verifica o número de comparações realizadas00085 _numero_de_comparacoes++;0008600087 //Verifica se algum elemento deve sofrer inversão

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 81: Documentation - LibrarySorting

78 File Documentation

00088 if (ev[index] > ev[index + 1])00089 {00090 ev.swap(index + 1,index);00091 houvetroca = true;00092 _numero_de_trocas++;00093 }0009400095 //Caso haja troca retorna o indice para o começo da lista00096 if(houvetroca) { index = 0; houvetroca = false; }00097 else { ++index;}00098 _numero_de_iteracoes++;00099 }00100 }00101 }0010200107 void InsertionSort::sort(ElementVector & ev)00108 {00109 Element temp;00110 int index;00111 unsigned int j, size_vector = ev.size();0011200113 for(j = 1; j < size_vector; j++)00114 {00115 temp = ev[j];0011600117 //O algoritmo faz pelo menos uma comparação antes de entrar no looping e uma00118 //iteração pois se as condições do cabeçalho condicional do próximo laço não00119 //forem aceitas o looping[for] não será executado.00120 _numero_de_iteracoes++;00121 _numero_de_comparacoes++;0012200123 //O restante das comparações são feitas pelo cabeçalho condicional do laço00124 for(index = j-1; index >= 0 && ev[index] > temp; index--)00125 {00126 ev[index + 1] = ev[index];00127 _numero_de_iteracoes++;00128 _numero_de_trocas++;00129 _numero_de_comparacoes++;00130 }0013100132 //Necessáriamente isso é apenas uma reatribuição quando a lista já se00133 //encontra ordenada, por isso comentamos o incremento do número de trocas00134 //_numero_de_trocas++;00135 ev[index + 1] = temp;00136 }00137 }0013800143 void SelectionSort::sort(ElementVector & ev)00144 {00145 register unsigned int index,j,minimum;00146 register unsigned int size_vector = ev.size();0014700148 for(j = 0; j < size_vector - 1; ++j)00149 {00150 minimum = j;0015100152 //Procura pelo índice com o menor elemento00153 for(index = j+1; index < size_vector; ++index)00154 {00155 _numero_de_comparacoes++;00156 _numero_de_iteracoes++;00157 if (ev[index] < ev[minimum]) minimum = index;00158 }0015900160 //Quando acha o menor elemento executa a troca. Necessáriamente isso é apenas

00161 //uma reatribuição quando a lista já se encontra ordenada.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 82: Documentation - LibrarySorting

5.6 SortingAlgorithms.cxx 79

00162 _numero_de_trocas++;00163 ev.swap(j,minimum);00164 }00165 }0016600170 void QuickPivotCentral::sort(ElementVector& ev){ QuickSort(ev, 0, ev.size() - 1)

; };0017100182 void QuickPivotCentral::QuickSort(ElementVector& ev, int BeginList, int EndList)00183 {00184 int i , j;00185 Element c, t;0018600187 if (BeginList < EndList)00188 {00189 c = ev[(BeginList + EndList) / 2];00190 i = BeginList; j = EndList;0019100192 while (i <= j)00193 {00194 while (ev[i] < c) { ++i; _numero_de_comparacoes++; _numero_de_iteracoes++;

}00195 while (c < ev[j]) { --j; _numero_de_comparacoes++; _numero_de_iteracoes++;

}0019600197 if (i <= j)00198 {00199 t = ev[i], ev[i] = ev[j], ev[j] = t;00200 ++i, --j;00201 _numero_de_trocas++;00202 }00203 _numero_de_iteracoes++;00204 }0020500206 //Segmento onde ocorre a chamada recursiva ao método00207 QuickSort(ev, BeginList, j);00208 QuickSort(ev, i, EndList);00209 }00210 }0021100215 void QuickPivotPeripheral::sort(ElementVector& ev){ QSort(ev, 0, ev.size() - 1);

};0021600223 void QuickPivotPeripheral::QSort(ElementVector& ev, int left, int right)00224 {00225 int new_right;0022600227 if (right > left)00228 {00229 new_right = Partition(ev, left, right);00230 QSort(ev,left, new_right - 1);00231 QSort(ev,new_right + 1,right);00232 }0023300234 return;00235 }0023600240 int QuickPivotPeripheral::Partition(ElementVector& ev, int left, int right)00241 {00242 register int i, j;0024300244 i = left;0024500246 for (j = left + 1; j <= right; j++)00247 {00248 _numero_de_iteracoes++;00249 _numero_de_comparacoes++;

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 83: Documentation - LibrarySorting

80 File Documentation

00250 if (ev[j] < ev[left])00251 {00252 ++i;00253 ev.swap(i,j);00254 _numero_de_trocas++;00255 }00256 }0025700258 //O elemento do limite da partição é trocado com o pivô. Necessáriamente isso00259 //é apenas uma reatribuição quando a lista já se encontra ordenada. Por isso00260 //comentamos o incremento na variável de troca.00261 //_numero_de_trocas++;00262 ev.swap(left,i);00263 return i;00264 }0026500269 void MergeSort::sort(ElementVector& ev){ MergeMethod(ev, 0, ev.size()); };0027000282 void MergeSort::MergeMethod(ElementVector& ev, int BeginList, int EndList)00283 {00284 if (BeginList < EndList -1)00285 {00286 int middle = (BeginList + EndList)/2;00287 MergeMethod(ev, BeginList, middle);00288 MergeMethod(ev, middle, EndList);00289 Merges(ev, BeginList, middle, EndList);00290 }00291 }0029200298 void MergeSort::Merges(ElementVector & ev, int BeginList, int Middle, int EndList

)00299 {00300 int i, j, k;00301 ElementVector w;0030200303 //Executa um resize na lista de elementos alocando o necessário para a00304 //intercalação dos elementos.00305 w.resize(EndList - BeginList);0030600307 //Estabelecendo os limites para a intercalação00308 i = BeginList; j = Middle; k = 0;0030900310 //Verifica quem deve ser intercalado00311 while( i < Middle && j < EndList)00312 {00313 if (ev[i] <= ev[j]) w[k++] = ev[i++];00314 else w[k++] = ev[j++];0031500316 //Executa analise de desempenho do algoritmo.00317 _numero_de_comparacoes++;00318 _numero_de_trocas++;00319 _numero_de_iteracoes++;00320 }0032100322 //Executa as intercalações finais.00323 while(i < Middle) { w[k++] = ev[i++]; _numero_de_iteracoes++; }00324 while(j < EndList) { w[k++] = ev[j++]; _numero_de_iteracoes++; }0032500326 //Copia o a lista auxiliar para a lista original00327 for( i = BeginList; i < EndList; ++i)00328 { ev[i] = w[i-BeginList]; _numero_de_iteracoes++; }0032900330 //Limpa a lista auxiliar ...00331 w.clear();00332 }0033300343 void ShellSort::sort(ElementVector& ev)

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 84: Documentation - LibrarySorting

5.6 SortingAlgorithms.cxx 81

00344 {00345 int h, size = ev.size();0034600347 for( h = 1; h < size; h = 3 * h + 1 );0034800349 do00350 {00351 //Tamanho do gap ou salto que sera dado de 3 em 3 dentro do compartimento...00352 h /= 3;0035300354 //Executando looping para verificação e ordenação ...00355 for( int i = h; i < size; ++i )00356 {00357 Element value = ev[i];00358 int j;0035900360 //O algoritmo faz pelo menos uma comparação antes de entrar no looping e um

a00361 //iteração pois se as condições do cabeçalho condicional do próximo laço nã

o00362 //forem aceitas o looping[for] não será executado.00363 _numero_de_iteracoes++;00364 _numero_de_comparacoes++;0036500366 for( j = i - h; j >= 0 && value < ev[j]; j -= h )00367 {00368 ev[j+h] = ev[j];00369 _numero_de_iteracoes++;00370 _numero_de_trocas++;00371 _numero_de_comparacoes++;00372 }0037300374 _numero_de_trocas++;00375 ev[j+h] = value;00376 }00377 }while( h > 1 );0037800379 }0038000393 void HeapSort::sort(ElementVector & ev)00394 {00395 int i = ev.size()/2, n = ev.size(), pai, filho;00396 Element t;0039700398 for (;;)00399 {00400 if (i > 0)00401 {00402 i--;00403 t = ev[i];00404 }00405 else00406 {00407 n--;00408 if (n == 0) return;00409 t = ev[n];00410 ev[n] = ev[0];00411 }0041200413 pai = i;00414 filho = i*2 + 1;0041500416 while (filho < n)00417 {00418 if ((filho + 1 < n) && (ev[filho + 1] > ev[filho]))00419 {00420 filho++;

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 85: Documentation - LibrarySorting

82 File Documentation

00421 _numero_de_comparacoes++;00422 }0042300424 if (ev[filho] > t)00425 {00426 ev[pai] = ev[filho];00427 pai = filho;00428 filho = pai*2 + 1;0042900430 _numero_de_comparacoes++;00431 _numero_de_trocas++;00432 }00433 else break;0043400435 _numero_de_iteracoes++;00436 }0043700438 ev[pai] = t;00439 //_numero_de_trocas++;00440 _numero_de_iteracoes++;00441 }00442 }0044300448 void InternalQuickSort::sort(ElementVector & ev)00449 {00450 //Executa o método de ordenação fornecido pela STL baseado no quicksort00451 ev.sort();00452 }0045300463 void GnomeSort::sort(ElementVector & ev)00464 {00465 //Controlador de indice de posicionamento00466 unsigned int index = 1;0046700468 //looping que executa as ordenações00469 while( index < ev.size() )00470 {00471 //Sempre executa uma comparação antes de modificar o índice00472 _numero_de_comparacoes++;00473 _numero_de_iteracoes++;00474 if((index == 0) || ( ev[index-1] <= ev[index] ))00475 {00476 index++;00477 }00478 else00479 {00480 _numero_de_trocas++;00481 ev.swap( index - 1, index );00482 --index;00483 }00484 }00485 }0048600492 void ShakerSort::sort(ElementVector& ev)00493 {00494 //Declaração e atribuição das variaveis de controle00495 int length, bottom, top, i; bool swapped = false;00496 length = ev.size(); bottom = 0; top = length - 1; swapped = false;0049700498 //Se não houver troca de posições ou o ponteiro que00499 //sobe ultrapassar o que desce, o vetor estará ordenado00500 while(swapped == 0 && bottom < top)00501 {00502 swapped = true;0050300504 //Este looping é a ida para a direita00505 for(i = bottom; i < top; i = i + 1)

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 86: Documentation - LibrarySorting

5.6 SortingAlgorithms.cxx 83

00506 {00507 //indo pra direita: testa se o próximo é maior00508 //indo pra direita: se o proximo é maior que o atual troca as posições00509 _numero_de_comparacoes++;00510 _numero_de_iteracoes++;00511 if(ev[i] > ev[i + 1])00512 {00513 ev.swap(i, i + 1);00514 swapped = false;00515 _numero_de_trocas++;00516 }00517 }0051800519 // Diminui o ‘top‘ porque o elemento com o maior valor00520 // já está na direita (atual posição top)00521 top = top - 1;0052200523 //Este looping é a ida para a esquerda00524 for(i = top; i > bottom; i = i - 1)00525 {00526 _numero_de_comparacoes++;00527 _numero_de_iteracoes++;00528 if(ev[i] < ev[i - 1])00529 {00530 ev.swap(i, i - 1);00531 swapped = false;00532 _numero_de_trocas++;00533 }00534 }0053500536 //Aumenta o ‘bottom‘ porque o menor valor já está na posição inicial00537 bottom = bottom + 1;00538 }00539 }0054000556 void CombSort::sort(ElementVector & ev)00557 {00558 //Variáveis de controle do tamanho do gap/salto/intervalo e troca de elementos00559 int gap = (int)ev.size();00560 int size_vector = (int)ev.size();00561 bool swapped = true;0056200563 //Verifica se o gap é maior que um ou se ainda está ocorrendo trocas00564 while (gap > 1 || swapped)00565 {00566 //Calculo do gap/salto/intervalo de aferição ou comparação dos elementos00567 if (gap > 1) { gap = (int) (gap / 1.3); }0056800569 //Variaveis de controle00570 int i = 0;00571 swapped = false;0057200573 //Looping onde ocorrerá verificações e trocas00574 while (i + gap < size_vector)00575 {00576 _numero_de_iteracoes++;00577 _numero_de_comparacoes++;00578 if (ev[i] > ev[i + gap])00579 {00580 _numero_de_trocas++;00581 ev.swap(i, i+gap);00582 swapped = true;00583 }00584 i++;00585 }00586 }00587 }

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 87: Documentation - LibrarySorting

84 File Documentation

5.7 SortingAlgorithms.h File Reference

#include "Element.h"

#include <iostream>

Include dependency graph for SortingAlgorithms.h:

SortingAlgorithms.h

Element.h iostream

vector cmath algorithm

This graph shows which files directly or indirectly include this file:

SortingAlgorithms.h

Sys-LibrarySorting.cpp

Classes

• class AbstractSorting• class BubbleSort• class BubbleSort2• class GnomeSort• class ShakerSort• class CombSort• class InsertionSort• class SelectionSort• class QuickPivotCentral• class QuickPivotPeripheral• class MergeSort• class ShellSort• class HeapSort• class InternalQuickSort

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 88: Documentation - LibrarySorting

5.8 SortingAlgorithms.h 85

5.8 SortingAlgorithms.h

00001 /*00002 * SortingAlgorithms.h00003 *00004 * Created on: 26/10/200900005 * Author: Administrador00006 */0000700008 #ifndef SORTINGALGORITHMS_H_00009 #define SORTINGALGORITHMS_H_0001000011 #include "Element.h"00012 #include <iostream>0001300017 class AbstractSorting00018 {00019 protected:00026 long double _numero_de_iteracoes;0002700032 long double _numero_de_trocas;0003300037 long double _numero_de_comparacoes;0003800039 public:00043 AbstractSorting();0004400050 void InitializeVariables(void);0005100056 long double IterationsNumber(void) { return _numero_de_iteracoes; };0005700062 long double InversionsNumber(void) { return _numero_de_trocas; };0006300068 long double ComparisonsNumber(void) { return _numero_de_comparacoes; };0006900073 virtual void sort(ElementVector& ev) = 0;0007400078 virtual ~AbstractSorting(){}00079 };0008000088 class BubbleSort: public AbstractSorting00089 {00090 public:00094 BubbleSort():AbstractSorting(){};0009500099 void sort(ElementVector& ev);00100 };0010100109 class BubbleSort2 : public AbstractSorting00110 {00111 public:00115 BubbleSort2():AbstractSorting(){};0011600120 void sort(ElementVector& ev);00121 };0012200132 class GnomeSort: public AbstractSorting00133 {00134 public:00138 GnomeSort():AbstractSorting(){};0013900143 void sort(ElementVector& ev);00144 };0014500151 class ShakerSort: public AbstractSorting00152 {00153 public:

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 89: Documentation - LibrarySorting

86 File Documentation

00157 ShakerSort():AbstractSorting(){};0015800162 void sort(ElementVector& ev);00163 };0016400180 class CombSort: public AbstractSorting00181 {00182 public:00186 CombSort():AbstractSorting(){};0018700191 void sort(ElementVector& ev);00192 };0019300198 class InsertionSort : public AbstractSorting00199 {00200 public:00204 InsertionSort():AbstractSorting(){};0020500209 void sort(ElementVector& ev);00210 };0021100216 class SelectionSort: public AbstractSorting00217 {00218 public:00222 SelectionSort():AbstractSorting(){};0022300227 void sort(ElementVector& ev);00228 };0022900233 class QuickPivotCentral : public AbstractSorting00234 {00235 public:00239 QuickPivotCentral():AbstractSorting(){};0024000244 void sort(ElementVector& ev);0024500259 void QuickSort(ElementVector& ev, int BeginList, int EndList);00260 };0026100265 class QuickPivotPeripheral : public AbstractSorting00266 {00267 public:00271 QuickPivotPeripheral():AbstractSorting(){};0027200276 void sort(ElementVector& ev);0027700287 void QSort(ElementVector& ev, int left, int right);0028800292 int Partition(ElementVector& ev , int left, int right);00293 };0029400298 class MergeSort : public AbstractSorting00299 {00300 public:00304 MergeSort():AbstractSorting(){};0030500309 void sort(ElementVector& ev);0031000322 void MergeMethod(ElementVector& ev, int BeginList, int EndList);0032300329 void Merges(ElementVector& ev, int BeginList, int Middle, int EndList);00330 };0033100341 class ShellSort: public AbstractSorting00342 {00343 public:00347 ShellSort():AbstractSorting(){};

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 90: Documentation - LibrarySorting

5.8 SortingAlgorithms.h 87

0034800352 void sort(ElementVector& ev);00353 };0035400367 class HeapSort: public AbstractSorting00368 {00369 public:00373 HeapSort():AbstractSorting(){};0037400378 void sort(ElementVector& ev);00379 };0038000385 class InternalQuickSort: public AbstractSorting00386 {00387 public:00391 InternalQuickSort():AbstractSorting(){};0039200396 void sort(ElementVector& ev);00397 };0039800399 #endif /* SORTINGALGORITHMS_H_ */

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 91: Documentation - LibrarySorting

88 File Documentation

5.9 Sys-LibrarySorting.cpp File Reference

#include <iostream>

#include "Element.h"

#include "SortingAlgorithms.h"

Include dependency graph for Sys-LibrarySorting.cpp:

Sys-LibrarySorting.cpp

iostream Element.h

SortingAlgorithms.h

vector cmath algorithm

Functions

• void ExecuteSort (AbstractSorting ∗as, ElementVector &ev)• int main (int argc, char ∗argv[ ])

5.9.1 Function Documentation

5.9.1.1 void ExecuteSort (AbstractSorting ∗ as, ElementVector & ev)

Function that tests sorting algorithms

Definition at line 14 of file Sys-LibrarySorting.cpp.

00014 { as->sort(ev); }

Here is the call graph for this function:

ExecuteSort AbstractSorting::sort

Here is the caller graph for this function:

ExecuteSort main

5.9.1.2 int main (int argc, char ∗ argv[ ])

Função para testes com a biblioteca.

Definition at line 19 of file Sys-LibrarySorting.cpp.

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 92: Documentation - LibrarySorting

5.9 Sys-LibrarySorting.cpp File Reference 89

00020 {00021 //Elements for sorting00022 ElementVector ev;00023 ev.add( Element(05.6) ); ev.add( Element(04.6) ); ev.add( Element(02.6) ); ev.

add( Element(10.2) );00024 ev.add( Element(11.4) ); ev.add( Element(10.5) ); ev.add( Element(07.1) ); ev.

add( Element(00.2) );0002500026 //Abstract sorting00027 MergeSort s;0002800029 //print elements00030 std::cout << "Unsorting elements: \t";00031 for(unsigned int i = 0; i < ev.size(); i++) std::cout << ev.at(i).value() << "\

t";0003200033 //Execute sorting00034 ExecuteSort(&s, ev);0003500036 //print elements00037 std::cout << std::endl << "Sorting elements: \t";00038 for(unsigned int i = 0; i < ev.size(); i++) std::cout << ev.at(i).value() << "\

t";0003900040 //measuring variables00041 std::cout << std::endl << "Inversions: \t\t" << s.InversionsNumber();00042 std::cout << std::endl << "Comparisons: \t\t" << s.ComparisonsNumber();00043 std::cout << std::endl << "Iterations: \t\t" << s.IterationsNumber();0004400045 return 0;00046 }

Here is the call graph for this function:

main

ElementVector::add

ElementVector::at

AbstractSorting::ComparisonsNumber

ExecuteSort

AbstractSorting::InversionsNumber

AbstractSorting::IterationsNumber

ElementVector::size

Element::value

ElementVector::push_back

AbstractSorting::sort

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 93: Documentation - LibrarySorting

90 File Documentation

5.10 Sys-LibrarySorting.cpp

00001 //============================================================================00002 // Name : Sys-LibrarySorting00003 // Author : Michel Alves dos Santos00004 // Version : 0.01 beta00005 //============================================================================0000600007 #include <iostream>00008 #include "Element.h"00009 #include "SortingAlgorithms.h"0001000014 void ExecuteSort(AbstractSorting* as, ElementVector& ev){ as->sort(ev); }0001500019 int main(int argc, char* argv[])00020 {00021 //Elements for sorting00022 ElementVector ev;00023 ev.add( Element(05.6) ); ev.add( Element(04.6) ); ev.add( Element(02.6) ); ev.

add( Element(10.2) );00024 ev.add( Element(11.4) ); ev.add( Element(10.5) ); ev.add( Element(07.1) ); ev.

add( Element(00.2) );0002500026 //Abstract sorting00027 MergeSort s;0002800029 //print elements00030 std::cout << "Unsorting elements: \t";00031 for(unsigned int i = 0; i < ev.size(); i++) std::cout << ev.at(i).value() << "\

t";0003200033 //Execute sorting00034 ExecuteSort(&s, ev);0003500036 //print elements00037 std::cout << std::endl << "Sorting elements: \t";00038 for(unsigned int i = 0; i < ev.size(); i++) std::cout << ev.at(i).value() << "\

t";0003900040 //measuring variables00041 std::cout << std::endl << "Inversions: \t\t" << s.InversionsNumber();00042 std::cout << std::endl << "Comparisons: \t\t" << s.ComparisonsNumber();00043 std::cout << std::endl << "Iterations: \t\t" << s.IterationsNumber();0004400045 return 0;00046 }

Generated on Sun Dec 4 13:13:28 2011 by Doxygen

Page 94: Documentation - LibrarySorting

Index

∼AbstractSortingAbstractSorting, 8

∼ElementElement, 22

∼ElementVectorElementVector, 25

_numero_de_comparacoesAbstractSorting, 10

_numero_de_iteracoesAbstractSorting, 10

_numero_de_trocasAbstractSorting, 10

absMaxValueElementVector, 26

AbstractSorting, 7∼AbstractSorting, 8_numero_de_comparacoes, 10_numero_de_iteracoes, 10_numero_de_trocas, 10AbstractSorting, 8ComparisonsNumber, 8InitializeVariables, 8InversionsNumber, 9IterationsNumber, 9sort, 9

addElementVector, 26

atElementVector, 26

BubbleSort, 11BubbleSort, 13sort, 13

BubbleSort2, 14BubbleSort2, 16sort, 16

clearElementVector, 27

CombSort, 18CombSort, 20sort, 20

ComparisonsNumberAbstractSorting, 8

Element, 22∼Element, 22Element, 22operator<, 22operator<=, 23operator>, 23value, 23, 24

Element.cxx, 71Element.h, 73ElementVector, 25

∼ElementVector, 25absMaxValue, 26add, 26at, 26clear, 27ElementVector, 25isEmpty, 27maxValue, 27minValue, 28push_back, 29resize, 29size, 29sort, 30swap, 30

ExecuteSortSys-LibrarySorting.cpp, 88

GnomeSort, 32GnomeSort, 34sort, 34

HeapSort, 36HeapSort, 38sort, 38

InitializeVariablesAbstractSorting, 8

InsertionSort, 40InsertionSort, 41sort, 42

InternalQuickSort, 43InternalQuickSort, 44sort, 45

InversionsNumberAbstractSorting, 9

Page 95: Documentation - LibrarySorting

92 INDEX

isEmptyElementVector, 27

IterationsNumberAbstractSorting, 9

mainSys-LibrarySorting.cpp, 88

maxValueElementVector, 27

MergeMethodMergeSort, 48

MergesMergeSort, 48

MergeSort, 46MergeMethod, 48Merges, 48MergeSort, 48sort, 49

minValueElementVector, 28

operator<Element, 22

operator<=Element, 23

operator>Element, 23

operator()PredicateSort, 51

PartitionQuickPivotPeripheral, 58

PredicateSort, 51operator(), 51

push_backElementVector, 29

QSortQuickPivotPeripheral, 58

QuickPivotCentral, 52QuickPivotCentral, 54QuickSort, 54sort, 55

QuickPivotPeripheral, 56Partition, 58QSort, 58QuickPivotPeripheral, 58sort, 59

QuickSortQuickPivotCentral, 54

resizeElementVector, 29

SelectionSort, 60

SelectionSort, 61sort, 62

ShakerSort, 63ShakerSort, 64sort, 65

ShellSort, 67ShellSort, 69sort, 69

sizeElementVector, 29

sortAbstractSorting, 9BubbleSort, 13BubbleSort2, 16CombSort, 20ElementVector, 30GnomeSort, 34HeapSort, 38InsertionSort, 42InternalQuickSort, 45MergeSort, 49QuickPivotCentral, 55QuickPivotPeripheral, 59SelectionSort, 62ShakerSort, 65ShellSort, 69

SortingAlgorithms.cxx, 76SortingAlgorithms.h, 84swap

ElementVector, 30Sys-LibrarySorting.cpp, 88

ExecuteSort, 88main, 88

valueElement, 23, 24

Generated on Sun Dec 4 13:13:28 2011 by Doxygen


Recommended