q. enumerate number of operations possible on


Q. Enumerate number of operations possible on ordered lists and arrays.  Write procedures to insert and delete an element in to array.                                                                                                          

Ans:

The ordered list is a container which contains a sequence of objects. Each object has a specific position in the sequence. In addition to the basic repertoire of operations supported by all search able containers, the ordered lists provide the following operations:

FindPosition

It is used to find the position of an object in the ordered list;

Operator or []

It is used to access the object at a given position in the ordered list;

Withdraw(Position&)

It is used to remove the object at a given position from the ordered list.

InsertAfter

It is used to insert an object into the ordered list after the object at a given position;

InsertBefore

It is used to insert an object into the ordered list before the object at a given position.

The procedure of inserting and deleteting an element into an array:-

void insert ( int *arr, int pos, int num )

/* inserts an element num at given position pos */

{

/* shift elements to right */

int i ;

for ( i = MAX - 1 ; i >= pos ; i-- )

arr[i] = arr[i - 1] ;

arr[i] = num ;

}

void del ( int *arr, int pos )

/* deletes an element from the given position pos */

{

/* skip to the desired position */

int i ;

for ( i = pos ; i < MAX ; i++ )

arr[i - 1] = arr[i] ;

arr[i - 1] = 0 ;

}

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: q. enumerate number of operations possible on
Reference No:- TGS0156483

Expected delivery within 24 Hours