intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Lecture Data Structures & Algorithms: Chapter 1

Chia sẻ: Na Na | Ngày: | Loại File: PPTX | Số trang:22

49
lượt xem
4
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Lecture Data Structures & Algorithms: Chapter 1 (C-Language) presented address, pointers, arrays, address of each element in an array, accessing & manipulating an array using pointers, another case of manipulating an array using pointers, two-dimensional array, pointer arrays, structures, structure pointers.

Chủ đề:
Lưu

Nội dung Text: Lecture Data Structures & Algorithms: Chapter 1

  1. DONG NAI UNIVERSITY OF TECHNOLOGY Data Structures & Algorithms
  2. DONG NAI UNIVERSITY OF TECHNOLOGY C-Language
  3. DONG NAI UNIVERSITY OF TECHNOLOGY 1. ADDRESS 2. POINTERS 3. ARRAYS 4. ADDRESS OF EACH ELEMENT IN AN ARRAY 5. ACCESSING & MANIPULATING AN ARRAY USING POINTERS 6. ANOTHER CASE OF MANIPULATING AN ARRAY USING POINTERS 7. TWO-DIMENSIONAL ARRAY 8. POINTER ARRAYS 9. STRUCTURES 10. STRUCTURE POINTERS
  4. DONG NAI UNIVERSITY OF TECHNOLOGY 1.ADDRESS For every variable there are two attributes: address and value In memory with address 2: value "Dave" In memory with address 5: value: 95.5 cout
  5. DONG NAI UNIVERSITY OF TECHNOLOGY 2. POINTERS 1. is a variable whose value is also an address. 2. A pointer to an integer is a variable that can store the address of that integer ia: value of variable &ia: address of ia *ia means you are printing the value at the location specified by ia
  6. DONG NAI UNIVERSITY OF TECHNOLOGY int i; //A int * ia; //B cout
  7. DONG NAI UNIVERSITY OF TECHNOLOGY Points to Remember: • Pointers give a facility to access the value of a variable indirectly. • You can define a pointer by including a * before the name of the variable. • You can get the address where a variable is stored by using &.
  8. 3. ARRAYS DONG NAI UNIVERSITY OF TECHNOLOGY a. An array is a data structure b. used to process multiple elements with the same data type when a number of such elements are known. c. An array is a composite data structure; that means it had to be constructed from basic data types such as array integers. int M[10]; for(int i = 0;i
  9. DONG NAI UNIVERSITY OF TECHNOLOGY 4. ADDRESS OF EACH ELEMENT IN AN ARRAY - Each element of the array has a memory address. void printdetail(int M[]) { for(int i = 0;i
  10. DONG NAI UNIVERSITY OF TECHNOLOGY 5. ACCESSING & MANIPULATING AN ARRAY USING POINTERS – You can access an array element by using a pointer. – If an array stores integers -> use a pointer to integer to access array elements.
  11. DONG NAI UNIVERSITY OF TECHNOLOGY void printarr_usingpointer(int M[]) { int *pi; pi=M; for(int i=0;i
  12. DONG NAI UNIVERSITY OF TECHNOLOGY 6. ANOTHER CASE OF MANIPULATING AN ARRAY USING POINTERS The array limit is a pointer constant : cannot change its value in the program. int a[5]; int *b; a=b; //error b=a; //OK
  13. DONG NAI UNIVERSITY OF TECHNOLOGY void printarr_usingpointer(int M[]) { for(int i=0;i
  14. DONG NAI UNIVERSITY OF TECHNOLOGY 7. TWO-DIMENSIONAL ARRAY int M[3][4]; 7 2 9 0 9 5 4 1 8 0 3 6
  15. DONG NAI UNIVERSITY OF TECHNOLOGY Column 0 Column 1 Column 2 Column 3 M[0][0] M[0][1] M[0][2] M[0][3] Row 0 7 2 9 0 M[1][0] M[1][1] M[1][2] M[1][3] Row 1 9 5 4 1 M[2][0] M[2][1] M[2][2] M[2][3] Row 2 8 0 3 6 Column index (or subscript) Row index (or subscript) Array name
  16. DONG NAI UNIVERSITY OF TECHNOLOGY void printarr_usingpointer(int M[][4]) { for(int i=0;i
  17. DONG NAI UNIVERSITY OF TECHNOLOGY for(int i=0;i
  18. DONG NAI UNIVERSITY OF TECHNOLOGY 8. POINTER ARRAYS l You can define a pointer array (similarly to an array of integers). l In the pointer array, the array elements store the pointer that points to integer values.
  19. void main() DONG NAI UNIVERSITY OF TECHNOLOGY void printarr(int *M[]) { { int *M[5]; cout
  20. DONG NAI UNIVERSITY OF TECHNOLOGY 9. STRUCTURES • Structures are used when you want to process data of multiple data types • But you still want to refer to the data as a single entity • Access data: structurename.membername
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2