Presentation is loading. Please wait.

Presentation is loading. Please wait.

©Brooks/Cole, 2003 Chapter 11 Data Structures. ©Brooks/Cole, 2003 Data Structure Data structure uses collection of related variables that can be accessed.

Similar presentations


Presentation on theme: "©Brooks/Cole, 2003 Chapter 11 Data Structures. ©Brooks/Cole, 2003 Data Structure Data structure uses collection of related variables that can be accessed."— Presentation transcript:

1 ©Brooks/Cole, 2003 Chapter 11 Data Structures

2 ©Brooks/Cole, 2003 Data Structure Data structure uses collection of related variables that can be accessed individually or as a whole. There are three types of data structures; 1.Array 2.Records 3.Linked List

3 ©Brooks/Cole, 2003 ARRAYSARRAYS 11.1

4 Figure 11-1 Twenty individual variables

5 ©Brooks/Cole, 2003 Figure 11-2 Processing individual variables Read 20 times Process 20 times Print 20 times Not efficient, you need a powerful data structure such as an array

6 ©Brooks/Cole, 2003 Figure 11-3 Arrays with subscripts and indexes

7 ©Brooks/Cole, 2003 Figure 11-4 Processing an array Loop Construct makes array processing easy Indexing is the method used to refer to the variable in the array.

8 ©Brooks/Cole, 2003 Figure 11-5 Array Applications - Frequency Arrays

9 ©Brooks/Cole, 2003 Figure 11-6 Histogram

10 ©Brooks/Cole, 2003 Figure 11-7- Part I Two-dimensional array

11 ©Brooks/Cole, 2003 Figure 11-8 Memory layout Row-major?

12 ©Brooks/Cole, 2003 Row-Major (methods for storing multidimensional arrays in linear m emory)

13 ©Brooks/Cole, 2003 RECORDSRECORDS 11.2

14 Records A record is a collection of related elements having a single name. Each element is called a field. A field is the smallest element that has meaning. The difference between an array and a record is that all elements in an array can be of the same type however elements in records can be of different type. Data in a record should be related to one object.

15 ©Brooks/Cole, 2003 Figure 11-9 Records

16 ©Brooks/Cole, 2003 The elements in a record can be of the same or different types. But all elements in the record must be related. Note:

17 ©Brooks/Cole, 2003 Accessing Individual Fields Read book P.220

18 ©Brooks/Cole, 2003 LINKEDLISTSLINKEDLISTS 11.3

19 Inked List A linked list is an ordered collection of data in which each element contains the location of the next element. Each element contains two parts: data and link. The data part holds the useful information. The link part is used to chain data. It contains the pointer (address) that identify the next element. Pointer variable also identifies the first element in the list. Singly linked list contains one link to a single successor

20 ©Brooks/Cole, 2003 Figure 11-10 Linked lists Null pointer Pointer variable

21 ©Brooks/Cole, 2003 Figure 11-11 Node

22 ©Brooks/Cole, 2003 Figure 11-12 1. Inserting a node 1. Allocate memory for new node 2. New node points to its successor 3. Predecessor node points to new node

23 ©Brooks/Cole, 2003 Figure 11-13 2. Deleting a node Allocate the node to be deleted Make predecessor points to the node successor

24 ©Brooks/Cole, 2003 Figure 11-14 Traversing a list- changing the value, printing Walking pointer to move from a node to a node


Download ppt "©Brooks/Cole, 2003 Chapter 11 Data Structures. ©Brooks/Cole, 2003 Data Structure Data structure uses collection of related variables that can be accessed."

Similar presentations


Ads by Google