TAILIEUCHUNG - Lecture Algorithms and data structures: Chapter 23 - Arrays & Strings

In computer science, binary search trees, sometimes called ordered or sorted binary trees, are a particular type of containers: data structures that store "items" (such as numbers, names etc.) in memory. This topic covers binary search trees: Abstract Sorted Lists, background, definition and examples,. | Review 1 Pointer Pointer Variables Dynamic Memory Allocation Functions Arrays & Strings 2 Array Array Elements Accessing array elements Declaring an array Initializing an array Two-dimensional Array Array of Structure String Array of Strings Examples Introduction Arrays Contain fixed number of elements of same data type Static entity- same size throughout the program An array must be defined before it is used An array definition specifies a variable type, a name and size Size specifies how many data items the array will contain An example 3 Array Elements The items in an array are called elements All the elements are of the same type The first array element is numbered 0 Four elements (0-3) are stored consecutively in the memory 4 Accessing array elements To access an element specify array name and array index number Syntax: arrayname[ arrayindex] to access 3rd element of array age we use age[2] age is the name of the array and 2 is the index number 5 Declaring an array when declaring an array, specify type of array array name number of elements arrayType arrayName [ numberofElements ] examples int results [10 ]; float myArray [50]; declaring multiple arrays of same type format similar to regular variables example: int b[5], x[10]; 6 Initializing an array when an array is defined then you can give values to each array elements example: int n[5]={1,2,3,4,5}; 7 if not enough initializing values, then the rightmost elements become 0 example: int n[5]={1,2,3}; same as int n[5]={1,2,3,0,0}; if int n[5]={0} then all elements are 0 if size of an array is less than the values assigned to elements then it is a syntax error if size of an array is not specified, then compiler determines it from the initializing values we don’t need to use array size when we initialize all the array elements example: int n[ ]={1,2,3,4,5}; 8 Array example #include int main () { int bills [] = {16, 2, 77, 40, 12071}; int n, result=0; for ( n=0 ; n<5 ; n++ ) { result += bills[n]; } .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.