ARRAY
ARRAY
ARRAY
Array: A set of data elements of same data type is called array. Array is a static data structure i.e., the memory
should be allocated in advance and the size is fixed. This will waste the memory space when used space is less than
a. Creation of a List.
Global Declaration:
Create Operation:
Procedure
Program
void create()
int n,i;
printf("\nEnter the no.of elements to be added in the list");
scanf("%d",&list[i]); index++;
else
printf("\nThe size is limited. You cannot add data into the list");
Insert Operation:
Procedure:
• If index is less than or equal to maxsize, then Make that position empty by altering the position of the
elements
in the list.
Program
void insert()
int i,data,pos;
printf("\nEnter the data to be inserted");
scanf("%d",&data);
scanf("%d",&pos);
if(index<maxsize)
for(i=index;i>=pos-1;i--)
list[i+1]=list[i];
index++;
list[pos-1]=data;
else
Deletion
Procedure
• Alter the position of the elements by performing an assignment operation, list[i-1]=list[i], where i value
ranges
void del()
int i,pos;
scanf("%d",&pos);
for(i=pos;i<=index;i++)
list[i-1]=list[i];
index--;
Display
Procedure
• Formulate a loop, where i value ranges from 0 to index (index denotes the index of the last element
in the array.
Program
void display()
{
int i; for(i=0;i<=index;i++) printf("\t%d",list[i]);
• An array size is fixed at the start of execution and can store only the limited number of elements.
• Insertion and deletion of array are expensive. Since insertion is performed by pushing the entire array
one position down and deletion is performed by shifting the entire array one position up.