Tutorials

Arrays


Array Traversal


Traversing an array means visiting each element of the array atleast once.

When we traverse any data structure, we access all the elements in that data structure starting from first to the last element.

 

Algorithm

Let arr[] be the array to be traversed. 

L be the lower bound and U be the upper bound of the array.

  1. Start the for loop
  2. Set i as counter initialized at L
  3. Iterate for i = L to U
  4. Visit each element. Print arr[i]
  5. End of the loop.
  6. Exit

//traverse array(a[ ]) in data structure


for(int i = 0; i<=n-1; i++){

//visit element or print as a[i]

}

 

 

  



Please Share this page
Views : 31
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!