Understand arrays and their usefulness.Understand records and the difference between an array and a record.. Understand the concept of a linked list and the difference between an array a
Trang 1Data Structures
Trang 2Understand arrays and their usefulness.
Understand records and the difference between an array and
a record
Understand the concept of a linked list and the difference
between an array and a linked list
After reading this chapter, the reader should
be able to:
Understand when to use an array and when to use a linked-list
Trang 3 organizing related pieces of data
allowing different operations to be performed on the data
The basic types of data structures include:
Trang 4A RRA Y S 11.1
Trang 5 Array
a 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.
Trang 6Figure 11-1 Twenty individual variables
Trang 7Figure 11-2 Processing individual variables
Trang 8Figure 11-3 Arrays with subscripts and indexes
Trang 9Figure 11-4 Processing an array
Trang 10Figure 11-5
Frequency array
Show the number of elements with the same value found in a series of numbers.
Trang 11Figure 11-6 Histogram
A pictorial representation of a frequency array
Trang 12Figure 11-7- Part I Two-dimensional array
Trang 13Figure 11-8 Memory layout
Trang 14RECORDS 11.2
Trang 15 Array: all elements – same type
Record: elements – same or different types
Trang 16Figure 11-9 Records
Trang 17The elements in a
same or different or different types
But all elements
in the record must be related
Note:
Trang 18LINK ED LISTS 11.3
Trang 19Linked 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
Trang 20Figure 11-10 Linked lists
Trang 21Figure 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
Trang 22Figure 11-12 Inserting
a node
Trang 23Figure 11-13
Deleting a node
Trang 24Figure 11-14 Traversing a list