Professional Documents
Culture Documents
Data Structures
OBJECTIVES
After reading this chapter, the reader should be able to:
Understand arrays and their usefulness.
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. files lists arrays records trees tables
11.1
ARRAYS
Array
Figure 11-2
Figure 11-3
Figure 11-4
Processing an array
Figure 11-5
Frequency array
Show the number of elements with the same value found in a series of numbers.
Figure 11-6
Histogram
Two-dimensional array
Figure 11-8
Memory layout
Row-major storage
11.2
RECORDS
Record
Record a collection of related elements, possibly of different types, having a single name. Each element in a record is called a field.
Difference
all elements same type Record: elements same or different types.
Array:
Figure 11-9
Records
Note:
The elements in a record can be of the same or different types. But all elements in the record must be related.
11.3
LINKED LISTS
Linked list
Linked list 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 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.
Figure 11-10
Linked lists
Figure 11-11
Node
Figure 11-12
Inserting a node
Figure 11-13
Deleting a node
Figure 11-14
Traversing a list