©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
©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
©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.
©Brooks/Cole, 2003
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.
©Brooks/Cole, 2003
The elements in a record can be The elements in a record can be of theof the
same or different types. But all same or different types. But all elementselements
in the record must be related. in the record must be related.
Note:Note:
©Brooks/Cole, 2003
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
©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
©Brooks/Cole, 2003
Figure 11-13
2. Deleting a nodeAllocate the node to be deleted
Make predecessor points to the node successor
Top Related