Arrays
An array is defined as a set of finite number of homogeneous elements or data items it means an array can contain one type of data only either all integers all floating point numbers or all characters
Arrays form an important part of almost all-programming languages. It provides a powerful feature and can be used as such or can be used to form complex data structures like stacks and queues. An array can be defined as an infinite collection of homogeneous (similar type) elements. This means that an array can store either all integers all floating point numbers all characters (array of character or string) or any other compels data type but all of same type. There are some important points to be pointed out about arrays.
Passing arrays to function
Arrays like other simple variables can be passed to function. To pass its name is writes inside the argument list in the call statement. Arrays are by default passed to function by call by reference method because array name is itself a pointer to the first memory location of the array. However we can pass individual array elements through call by value method also.
Insertion in one-dimensional array
Let we have an array a[6] = {1,5,7,22,6,90} ;
Insertion of a new element in an array can be done in two ways:
1. Insertion at the end of array.
2. Insertion at required position.
Inserting an element at the end of an array can be easily done provided the memory space allocated for the array is large enough to accommodate the additional element.
a[0]
a[1]
a[2]
a[3]
a[4]
a[5]
a[6]
a[7]
a[8]
a[9]
|
1
5
7
6
22
90
0
0
0
0
|
a[0]
a[1]
a[2]
a[3]
a[4]
a[5]
a[6]
a[7]
a[8]
a[9]
|
1
5
7
6
22
90
0
0
0
|
a[0]
a[1]
a[2]
a[3]
a[4]
a[5]
a[6]
a[7]
a[8]
a[9]
|
1
5
7
6
20
22
90
0
0
0
|
Position for 20
Original Array Elements shifted Array after insertion
Downwards
Fig. 3.1 inserting element in an array
For inserting the element at required position, elements must be moved downwards to new locations. To accommodate the new element and keep the order of the elements
Suppose we want to insert 20 in array insert (a, len, pos, num,) where a is linear array Len be total no. of elements within array pos is the position at which number num will be inserted.
Data Structure & Algorithms Assignment Help, Live Experts
Struggling with data structure problems? Data structure subject is quite tough to learn? Need quick assistance in data structure questions? ExpertsMind.com is right place for you where your search ends, We at ExpertsMind offer online data structure assignment help, data structure homework help and data structure and algorithms question's answers by best online support by qualified tutors.
ExpertsMind.com - Arrays Assignment Help, Arrays Homework Help, Arrays Assignment Tutors, Arrays Solutions, Arrays Answers, Classification or Data Structure Assignment Tutors