Operations on Array - Data Structures

4
We have already discussed about Arrays in our previous post. In this post we are going to discuss about operations that we can perform on array.



Operations On Array:

We can can perform following operations on array:
  • Traversal - Printing Elements of array.
  • Insertion - Adds an element at a given index.
  • Deletion -  deletes an element at a given index.
  • Searching - Searches an element using a given index or by value.
We can also perform other operations like Sorting in Ascending and Descending Order.
Let's look into these individually.

Traversing:

Visiting or Printing every element of array is known as Traversing.
Now the question arises why traversal?

To store elements or print elements.

An array can easily be traversed using for loop in C.
int arr[5]={1,3,5,11,20};

Approach:

  • Start a loop from 0 to N-1, where N is the Size of array.
            for(i=0; i<N-1; i++);                      [i = index]
  • Access every element of array with help of
             arr[index]
  • Print the elements 
            printf("%d", arr[i]);

This was all for now.

In next post we will discuss about Insertion, Deletion and Searching in an array.




Post a Comment

4Comments
Post a Comment