1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Data Structures & Algorithms pptx

13 429 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

Tiêu đề Data Structures & Algorithms
Tác giả P. S. Deshpande, O. G. Kakde
Trường học Charles River Media, Inc.
Chuyên ngành Data Structures & Algorithms
Thể loại Tài liệu
Năm xuất bản 2025
Thành phố Hingham
Định dạng
Số trang 13
Dung lượng 199,22 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

– A data structure is defined by z1 the logical arrangement of data elements, combined with z2 the set of operations we need to access the elements... z Example:library books book

Trang 1

Data Structures &

Algorithms

Week1

Contents

z Textbook

z Grade

z Software

Trang 2

z C & Data Structures

P S Deshpande, O G Kakde

Hingham, Massachusetts

Grade

z Midterm test (Lab)

z Final test (Lab)

z Project (working on group)

z Multiple choice test

z How to Grade

Trang 3

Software: C/C++ edittor

z C-Free is a professional C/C++ integrated

development environment (IDE) that support

multi-compilers Use of this software, user can edit, build,

run and debug programs freely

With C/C++ source parser included

Trang 4

C/C++ edittor: demo

z Find max of 3 numbers: a,b,c

CHAPTER 0: INTRODUTION

z What is Data Structures?

A data structure is defined by

z(1) the logical arrangement of data elements,

combined with

z(2) the set of operations we need to access the

elements.

Trang 5

Atomic Variables

z Atomic variables can only store one value at

a time.

int num;

float s;

z A value stored in an atomic variable cannot

be subdivided.

What is Data Structures?

z Example:library

(books)

book requires knowledge

of the arrangement of the

books

through the librarian

the logical arrangement of data elements, combined with

the set of operations we need to access the elements.

Trang 6

Basic Data Structures

z Structures include

What is Algorithm?

z Algorithm:

result

zExample: Find an element

1

2 3

4 5 6 7

Trang 7

Chapter 0: C LANGUAGE

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

Trang 8

Chapter 0: C LANGUAGE

1. ADDRESS

For every variable there are two attributes:

address and value

cout << "Value of 'y' is: " << y << "\n";

cout << "Address of 'y' is: " << &y << "\n\n";

In memory with address 3: value: 45

In memory with address 2: value "Dave"

Chapter 0: C LANGUAGE

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

Trang 9

Chapter 0: C LANGUAGE

int i; //A

int * ia; //B

cout<<"The address of i "<< &i << " value="<<i <<endl;

cout<<"The address of ia " << &ia << " value = " << ia<< endl;

i = 10; //C

ia = &i; //D

cout<<"after assigning value:"<<endl;

cout<<"The address of i "<< &i << " value="<<i <<endl;

cout<<"The address of ia " << &ia << " value = " << ia<< " point to: "<< *ia;

Chapter 0: C LANGUAGE

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 &.

Trang 10

Chapter 0: C LANGUAGE

3 ARRAYS

1. An array is a data structure

2. used to process multiple elements with the same data

type when a number of such elements are known

3. An array is a composite data structure; that means it

had to be constructed from basic data types such as

array integers.

1. int a[5];

2 for(int i = 0;i<5;i++)

1 {a[i]=i; }

Chapter 0: C LANGUAGE

4 ADDRESS OF EACH ELEMENT IN AN

ARRAY

Each element of the array has a memory

address.

void printdetail(int a[])

{

for(int i = 0;i<5;i++)

{

cout<< "value in array “<< a[i] <<“ at address: “ << &a[i]);

}

Trang 11

Chapter 0: C LANGUAGE

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.

Chapter 0: C LANGUAGE

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

It works correctly even using a++ ???

Trang 12

Chapter 0: C LANGUAGE

7 TWO-DIMENSIONAL ARRAY

int a[3][2];

Chapter 0: C LANGUAGE

8 POINTER ARRAYS

z You can define a pointer array (similarly to an array of

integers)

z In the pointer array, the array elements store the

pointer that points to integer values.

Trang 13

Chapter 0: C LANGUAGE

9 STRUCTURES

z Structures are used when

you want to process data of

multiple data types

z But you still want to refer to

the data as a single entity

z Access data:

structurename.membernam

e

Chapter 1: C LANGUAGE

10 STRUCTURE POINTERS

Process the structure using a structure pointer

Ngày đăng: 20/01/2014, 03:20

TỪ KHÓA LIÊN QUAN

w