Array in Data Structure:
- An array is a linear type of data structure.
- Definition: Array is a set of similar type of (homogeneous) data.
- The arrangement in an array in a systematic order as a sequential.
- An array stored in a systematic order it given and sequential index.
- Array index starts with zero.
- Each array element can be accessed by its index.
Initializing array: Specifies the number of an element we want to store that is the size of an array.
Assigning: This operation assigns a value to an array.
Example: arr=1; arr=2;
The operation performed on an array
- Adding element
- Deleting element
- Sorting element
- Searching element
- Re-arranging element
- For performing a matrix operation
Application of array in data structure
- Sorting Elements
- CPU Scheduling
- Recursive Function
Advantages of array
- Collection of a homogeneous element.
- It has an index.
- We can access any element by index.
- To implement data structure like a stack, queue.
Disadvantages of array
- We must know how many elements to store.
- An array has a fixed size that is memory allocated to an array cannot be increased or reduced.
- If we allocated more memory then we are using then memory will be wasted.
- It is stored in a consecutive memory location so insertion and deletion take more time.
Array simple program
int arr,j; // Initilizing array
for(i=0;i<5;i++) // taking array input
printf("%d",arr[i]); // Printing our array
Output of program
10 20 30 40 50
10 20 30 40 50array in Data Structure
- C Program to Find the Largest Two Numbers in a given Array
- Remove null values and empty strings from given string array
- Arrays in cpp
- C program to find sum of the array elements using pointers
- Sort array in descending order
- Reverse array in c
- C Program to Insert an Element in a Specified Position in a given Array