Wednesday, June 5, 2013

How can you use Array as an ADT?


Let A be the array the store N elements of type T. Then following set of operation can be performed on A:-
·         create(A): create an empty array A
·         insert(A,i,x): Insert an element x on the i location of an array A, if i is a valid location.
·         search(A,item): search the element ‘item’ in an array A and return the index of the ‘item’ if found otherwise return -1, to indicate that the searched item is not found.
·         sort(A): sort the elements of an array A in ascending or descending order.
·         traverse(A): Display all the elements of an array A.
·         merge(A1,N1,A2,N2,A,N): Merge the N1 elements from array A1 and N2 elements from array A2 into new array A of size N=N1+N2. The data type of array A1, A2 and A must be same.

No comments:

Post a Comment