انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة

Array

الكلية كلية العلوم للبنات     القسم قسم الحاسبات     المرحلة 2
أستاذ المادة اسراء عبد الله حسين علي الدليمي       11/12/2016 19:38:06
Array
Is an object that consists of a sequence of elements that are numbered 0,1,2,....... the element numbers are called index numbers. Array elements can be accessed by their index numbers using the subscript operator [] , as a[0], a[1], a[2], and soon. Arrays are widely used because they are so efficient.
One -Dimensional arrays
Is a data structure consist of a set of elements, which are all of the same data type. Characterized by the fact a fixed size does not change.
Store array in memory is as follow:
Ex:-
A[4]
A=[2,3,4,5]
A[0]=2 , A[1]=3 , A[2]=4 , A[3]=5

Relative addresses and are not real

Base addresses
2 100
3 101
4 102
5 103
Memory



General equation that are used to determine the address for any element in memory to one dimension array.
Loc(name[I])= Base address + (I)
name : name array
Base address : represent the absolute location of the first cell in the array.
I : represent the index .
1- Loc(A[3]) = 100 + (3) = 103 .
2- Find the Loc(A[2])????.

Two Dimension-Arrays
The process of transfer of the logical structure for two-dimension array to memory is perform by use two way:
1) Row - wise method.
2) Column - wise method.

Ex: A =

A[0][0]= 2 , A[0][1] = 3, A[1][0]=5 , A[1][1]=6
1) Row - wise
Base addresses
2 100
3 101
5 102
6 103
Memory
Loc(A[I,J])= Base address + I * m+ J
where (m ) represent the number of column
Loc(A[1][0])= 100 + 1*2+0 = 102 .
2) Column - wise
Base addresses
2 100
5 101
3 102
6 103
Memory

Loc(A[I,J])= Base address + J * n+ I
where (n ) represent the number of row
Loc(A[0][0])= 100 + 0*2+0 = 100 .

Three Dimensional Array
int A[M,N,R]
Calculated the location of the element A[I,J,K] for array as follow:-
1) Row - wise method.
Loc(A[I, J, k])= Base address +( M*N*K)+N*I+J

2) Column - wise method.
Loc(A[I, J, k])= Base address +( M*N*K)+M*J+I

Ex:- int A[8][5][7]
Find the location of the A[5,3,6]??? , Base address= 900.
1) Row - wise method.
The dimensions of array are :
M=8, N=5, R=7 i=5, j=3, k=6
Loc(A[I, J, k])= Base address +( M*N*K)+N*I+J
Loc(A[5,3,6])=900+(8*5*6)+5*5+3
= 900+240+28
= 1168


2) Column - wise method.
Loc(A[I, J, k])= Base address +( M*N*K)+M*J+I
Loc(A[5,3,6])=900+(8*5*6)+8* 3+5
= 900+ 240+29
=1169



المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .