24
Chapter 11 Data Structures

Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Embed Size (px)

Citation preview

Page 1: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Chapter 11

Data Structures

Page 2: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Understand Understand arraysarrays and their usefulness. and their usefulness.

Understand Understand recordsrecords and the difference between an array and and the difference between an array and a record.a record.

Understand the concept of a Understand the concept of a linked listlinked list and the difference and the differencebetween an array and a linked list.between an array and a linked list.

After reading this chapter, the reader should After reading this chapter, the reader should be able to:be able to:

OOBJECTIVESBJECTIVES

Understand Understand when to use an arraywhen to use an array and and when to use a linked-listwhen to use a linked-list..

Page 3: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Data Structures Data structure

uses a collection of related variables that can be accessed individually or as a whole.

Data structure a scheme for organizing related pieces of data. allowing different operations to be performed on the data.

The basic types of data structures include: files lists arrays records trees tables

Page 4: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

ARRAYSARRAYSARRAYSARRAYS11.111.1

Page 5: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Array

Arraya fixed-size, sequenced collection of elements of the same data type.

The subscripts indicate the ordinal number of the element counting from the beginning of the array.

Page 6: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-1Twenty individual variables

Page 7: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-2 Processing individual variables

Page 8: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-3 Arrays with subscripts and indexes

Page 9: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-4 Processing an array

Page 10: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-5 Frequency array Show the number of elements with the same

value found in a series of numbers.

Page 11: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-6 Histogram

A pictorial representation of a frequency array.

Page 12: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-7- Part I Two-dimensional array

Page 13: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-8 Memory layout

Row-major storage

Page 14: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

RECORDSRECORDSRECORDSRECORDS11.211.2

Page 15: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Record

Recorda collection of related elements, possibly of different types, having a single name.

Each element in a record is called a field.

Difference Array: all elements – same type Record: elements – same or different types.

Page 16: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-9 Records

Page 17: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

The elements in a The elements in a recordrecord can be can be of theof the

samesame or or differentdifferent types. types.

But all elementsBut all elementsin the record must be related.in the record must be related.

Note:Note:

Page 18: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

LINKEDLINKEDLISTSLISTS

LINKEDLINKEDLISTSLISTS

11.311.3

Page 19: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Linked list

Linked listan ordered collection of data in which each element contains the location of the next element.

Each element contains two parts: data and link. The link contains a pointer (an address) that identifies the

next element in the list.

Singly linked list The link in the last element contains a null pointer,

indicating the end of the list.

Page 20: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-10 Linked lists

Page 21: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-11 Node

Nodes : the elements in a linked list.

The nodes in a linked list are called self-referential records. Each instance of the record contains a pointer to another

instance of the same structural type.

Page 22: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-12 Inserting a node

Page 23: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-13Deleting a node

Page 24: Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the

Figure 11-14 Traversing a list