Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lecture # 8
DATA STRUCTURES
(Introduction to Data Structures and Arrays)
1
( 1 – حال201( حاسب آلـى: المقـرر
- They are used to organize data and provide various operations upon data.
- Arrays, linked lists, stacks and queues are examples of linear data structures in
which values are stored in a sequence.
- Tree, graph, table and sets are examples of non-linear data structures.
2
( 1 – حال201( حاسب آلـى: المقـرر
Arrays
1. What is an array
- An array is a finite collection of similar elements.
2. Declaration of an array
Arrays must be declared before they can be used in the program.
Example :
int a[10];
- Here the range of array starts from 0-9 ,where 0 is the lower bound and 9 is the
upper bound.
3
( 1 – حال201( حاسب آلـى: المقـرر
3. Initializing an Array
- Initial values are assigned to each element of an array by enclosing the values in
braces { }.
- For example:
- int a[5]={11,3,5,2,9};
11 3 5 2 9
A [2] = 5.
5. Multidimensional Arrays
Multidimensional arrays can be defined as "arrays of arrays".
Number of columns
Number of rows
Name of Array
Data type
4
( 1 – حال201( حاسب آلـى: المقـرر
Example
0 1 2 3
0 22 23 4 20
1 12 9 5 2
33 54 19 29
2
To access 20 we write: