Posts

Showing posts with the label user defined data structures

2D Array - Data Structures and Algorithm.(4)

Image
  2D array can be defined as an array of arrays. The 2D array is organized as matrices which can be represented as the collection of rows and columns. However, 2D arrays are created to implement a relational database look alike data structure. It provides ease of holding bulk of data at once which can be passed to any number of functions wherever required. How to declare 2D Array The syntax of declaring two dimensional array is very much similar to that of a one dimensional array, given as follows. int  arr[max_rows][max_columns]; however, It produces the data structure which looks like following. Above image shows the two dimensional array, the elements are organized in the form of rows and columns. First element of the first row is represented by a[0][0] where the number shown in the first index is the number of that row while the number shown in the second index is the number of the column. How do we access data in a 2D array Due to the fact that the elements of 2D arrays can be ran

Array Implementation In Data Structure And Algorithms (3)

So, in our previous Data structures and algorithms (series) Data Structures and Algorithms - Arrays (codin-india.blogspot.com) we saw how array used and in this blog we learn  how to implement array in Data structures and algorithm. Traverse Operation This operation is to traverse through the elements of an array. Example Following program traverses and prints the elements of an array: #include <stdio.h> main () { int LA [] = { 1 , 3 , 5 , 7 , 8 }; int item = 10 , k = 3 , n = 5 ; int i = 0 , j = n ; printf ( "The original array elements are :\n" ); for ( i = 0 ; i < n ; i ++) { printf ( "LA[%d] = %d \n" , i , LA [ i ]); } } When we compile and execute the above program, it produces the following result − Output The original array elements are : LA[0] = 1 LA[1] = 3 LA[2] = 5 LA[3] = 7 LA[4] = 8 Insertion Operation Insert operation is to insert one or more data elements into an array. Based on the