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

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 ;

}

Posted Date: 7/11/2012 1:22:58 AM | Location : United States







Related Discussions:- Number of operations possible on ordered lists and arrays, Assignment Help, Ask Question on Number of operations possible on ordered lists and arrays, Get Answer, Expert's Help, Number of operations possible on ordered lists and arrays Discussions

Write discussion on Number of operations possible on ordered lists and arrays
Your posts are moderated
Related Questions
HOW LINKED LIST HEADER WORKS? HOW TO INSERT AND DELETE ELEMENTS IN LINKED LIST?

What do you understand by tree traversal? The algorithm walks by the tree data structure and performs some computation at everynode in the tree. This process of walking by the

RENDERING, SHADING AND COLOURING By introducing hidden line removal we have already taken one step away from wire-frame drawings towards being able to realistically model and d

Warnock's Algorithm An interesting approach to the hidden-surface problem was presented by Warnock. His method does not try to decide exactly what is happening in the scene but

Program: Creation of Doubly Linked List OUTPUT Input the values of the element -1111 to come out : 1 Input the values of the element -1111 to come out : 2 Inpu

the above title please send give for the pdf file and word file

Explain binary search with an example

By changing the NULL lines in a binary tree to the special links called threads, it is possible to execute traversal, insertion and deletion without using either a stack or recursi

Ask queConsider the following functional dependencies: Applicant_ID -> Applicant_Name Applicant_ID -> Applicant_Address Position_ID -> Positoin_Title Position_ID -> Date_Position_O

how to do a merge sorting