Number of operations possible on ordered lists and arrays, Data Structure & Algorithms

Assignment Help:

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 ;

}


Related Discussions:- Number of operations possible on ordered lists and arrays

Merging, merging 4 sorted files containing 50 10 25 and 15 records will tak...

merging 4 sorted files containing 50 10 25 and 15 records will take time

Frequency counts for all statements, Evaluate the frequency counts for all ...

Evaluate the frequency counts for all statements in the following given program segment. for (i=1; i ≤ n; i ++) for (j = 1; j ≤ i; j++) for (k =1; k ≤ j; k++) y ++;

Graph traversal schemes, Various graph traversal schemes Graph Traversa...

Various graph traversal schemes Graph Traversal Scheme. In many problems we wish to investigate all the vertices in a graph in some systematic order. In graph we often do no

Process of in-order traversal, In-order Traversal  This process when ex...

In-order Traversal  This process when executed iteratively also needs a stack and a Boolean to prevent the implementation from traversing any portion of a tree twice. The gener

Explain the concept of colouring, Colouring The use of colours in CAD/C...

Colouring The use of colours in CAD/CAM has two main objectives : facilitate creating geometry and display images. Colours can be used in geometric construction. In this case,

Multiple stacks, how multiple stacks can be implemented using one dimension...

how multiple stacks can be implemented using one dimensional array

What are the things require to implement abstract data types, What are the ...

What are the things require to implement ADT Abstract data types are very useful for helping us understand the mathematical objects which we use in our computations but, of cou

Explain the assertions in ruby, Explain the Assertions in Ruby Ruby off...

Explain the Assertions in Ruby Ruby offers no support for assertions whatever. Moreover, because it's weakly typed, Ruby doesn't even enforce rudimentary type checking on opera

Graph search using iterative deepening, Prove that uniform cost search and ...

Prove that uniform cost search and breadth- first search with constant steps are optimal when used with the Graph-Search algorithm (see Figure). Show a state space with varying ste

Explain open addressing, Open addressing The easiest way to resolve a c...

Open addressing The easiest way to resolve a collision is to start with the hash address and do a sequential search by the table for an empty location.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd