Page 1
Introduction to C++ Introduction to C++ Programming LanguageProgramming Language
Jeon, Seokhee
Assistant ProfessorAssistant ProfessorDepartment of Computer Engineering,Department of Computer Engineering,
Kyung Hee University, KoreaKyung Hee University, Korea
Page 2
CHAPTER 8CHAPTER 8ArrayArray
Page 3
Derived TypesDerived Types
Page 4
Ten VariablesTen Variables
Page 5
Processing Ten VariablesProcessing Ten Variables
Page 6
An Array of ScoresAn Array of Scores
Page 7
The Scores ArrayThe Scores Array
Page 8
Loop for Ten ScoresLoop for Ten Scores
Page 9
Declaring and defining arraysDeclaring and defining arrays
Page 10
Initializing arraysInitializing arrays
Page 11
Exchanging scores-the wrong wayExchanging scores-the wrong way
Page 12
Exchanging scores with temporary Exchanging scores with temporary variablevariable
Page 13
Squares ArraySquares Array
Page 14
Print Input ReversedPrint Input Reversed
Page 15
Passing individual elements to functionPassing individual elements to function
Page 16
Passing arrays—averagePassing arrays—average
Prevent x from being changed.
Use x just for refering
Prevent x from being changed.
Use x just for refering
Page 17
Changing values in arraysChanging values in arrays
Page 18
Random Number Random Number PermutationPermutation
Page 19
SORTING IN ARRAYSORTING IN ARRAY
Page 20
Selection sort conceptSelection sort concept
Page 21
Selection sort exampleSelection sort example
Page 22
Selection Sort CodeSelection Sort Code
Page 23
Bubble sort conceptBubble sort concept
Page 24
Bubble sort exampleBubble sort example
Page 25
Bubble Sort CodeBubble Sort Code
Page 26
Insertion sort conceptInsertion sort concept
Page 27
Insertion sort exampleInsertion sort example
Page 28
Insertion Sort CodeInsertion Sort Code
Page 29
SEARCHING IN ARRAYSEARCHING IN ARRAY
Page 30
Search conceptSearch concept
Page 31
Sequential SearchSequential Search
Page 32
Unsuccessful searchUnsuccessful search
Page 33
Sequential Search CodeSequential Search Code
Page 34
Binary search exampleBinary search example
Note that the list is Note that the list is already sorted already sorted
Page 35
Unsuccessful binary search exampleUnsuccessful binary search example
Page 36
Binary Search CodeBinary Search Code
Page 37
Useful materials on sorting and Useful materials on sorting and searching algorithmssearching algorithms
• http://www.sorting-algorithms.com/
• http://www.cosc.canterbury.ac.nz/mukundan/dsal/appldsal.html
• http://www.cs.auckland.ac.nz/~jmor159/PLDS210/alg_anim.html
Page 38
Two-dimensional arrayTwo-dimensional array
Page 39
Array of arraysArray of arrays
Page 40
Memory layoutMemory layout
Page 41
Passing a row Passing a row
Page 42
Calculate average of integers in arrayCalculate average of integers in array
Page 43
Fill MatrixFill Matrix
Page 44
A three-dimensional array (3 x 5 x 4)A three-dimensional array (3 x 5 x 4)
Page 45
C++ view of three-dimensional arrayC++ view of three-dimensional array
Page 46
Initializing a three-dimensional arrayInitializing a three-dimensional array