1. Trang chủ
  2. » Tất cả

Cấu trúc dữ liệu và thuật toán ch01 intro

41 1 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 41
Dung lượng 1,24 MB

Nội dung

Data Structure and Algorithms [CO2003] Chapter - Introduction Lecturer: Duc Dung Nguyen, PhD Contact: nddung@hcmut.edu.vn Faculty of Computer Science and Engineering Hochiminh city University of Technology Contents Basic concepts Revision Lecturer: Duc Dung Nguyen, PhD Contact: nddung@hcmut.edu.vn Data Structure and Algorithms [CO2003] / 38 Basic concepts What is Data? (Source: datorama.com) Lecturer: Duc Dung Nguyen, PhD Contact: nddung@hcmut.edu.vn Data Structure and Algorithms [CO2003] / 38 What is Data? Data Data is information that has been translated into a form that is more convenient to calculate, analyze Example • Numbers, words, measurements, observations or descriptions of things • Qualitative data: descriptive information, • Quantitative data: numerical information (numbers) • Discrete data can only take certain values (like whole numbers) • Continuous data can take any value (within a range) Lecturer: Duc Dung Nguyen, PhD Contact: nddung@hcmut.edu.vn Data Structure and Algorithms [CO2003] / 38 Data type Class of data objects that have the same properties Data type A set of values A set of operations on values Example Type integer floating point character Values Operations −∞, , −2, −1, 0, 1, 2, , ∞ −∞, , 0.0, , ∞ \0, , ‘A’, ‘B’, , ‘a’, ‘b’, , ∼ ∗, +, −, %, /, ++, −−, ∗, +, −, /, , Lecturer: Duc Dung Nguyen, PhD Contact: nddung@hcmut.edu.vn Data Structure and Algorithms [CO2003] / 38 Data structure What is a data structure? A combination of elements in which each is either a data type or another data structure A set of associations or relationships (structure) that holds the data together Example An array is a number of elements of the same type in a specific order Lecturer: Duc Dung Nguyen, PhD Contact: nddung@hcmut.edu.vn 13 21 34 Data Structure and Algorithms [CO2003] / 38 Abstract data type The concept of abstraction: • Users know what a data type can • How it is done is hidden Definition An abstract data type is a data declaration packaged together with the operations that are meaningful for the data type Declaration of data Declaration of operations Encapsulation of data and operations Lecturer: Duc Dung Nguyen, PhD Contact: nddung@hcmut.edu.vn Data Structure and Algorithms [CO2003] / 38 Abstract data type Figure 1: Abstract data type model (source: Slideshare) Lecturer: Duc Dung Nguyen, PhD Contact: nddung@hcmut.edu.vn Data Structure and Algorithms [CO2003] / 38 Example: List Interface • Data: sequence of elements of a particular data type • Operations: accessing, insertion, deletion Implementation • Array • Linked list Lecturer: Duc Dung Nguyen, PhD Contact: nddung@hcmut.edu.vn Data Structure and Algorithms [CO2003] / 38 Classes Initialization • Member initialization: c l a s s Rectangle { i n t width ; const i n t height ; public : Rectangle ( int , int ) ; }; Rectangle ( int x , int y ) : width = x ; } height (y) { i n t main ( ) { Rectangle rectA (3 ,4); } Lecturer: Duc Dung Nguyen, PhD Contact: nddung@hcmut.edu.vn Data Structure and Algorithms [CO2003] 24 / 38 Pointers Definition A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location Address-of operator (&) The address of a variable can be obtained by preceding the name of a variable with an ampersand sign (&), known as address-of operator For example: p = &v a l u e ; Dereference operator (*) To access the variable pointed to by a pointer, we precede the pointer name with the dereference operator (*) v a l u e = ∗p ; Lecturer: Duc Dung Nguyen, PhD Contact: nddung@hcmut.edu.vn Data Structure and Algorithms [CO2003] 25 / 38 Pointers p 1000 value 93 999 1000 1001 p = &v a l u e ; v a l u e = ∗p ; Lecturer: Duc Dung Nguyen, PhD Contact: nddung@hcmut.edu.vn Data Structure and Algorithms [CO2003] 26 / 38 Pointers Example i n t main ( ) { i n t v1 = , v2 = ; i n t ∗ p1 , ∗ p2 ; p1 = &v1 ; p2 = &v2 ; ∗ p1 = ; ∗ p2 = ∗ p1 ; p1 = p2 ; ∗ p1 = ; c o u t

Ngày đăng: 25/03/2023, 07:21

w