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

Use a random number generator to create 10 numbers, Use a random number gen...

Use a random number generator to create 10 numbers between 1 and 1000 and store them in 2 different arrays.  The first array should contain the numbers as they are generated.  The

Doubly linked list having n nodes, The time required to delete a node x fro...

The time required to delete a node x from a doubly linked list having n nodes is O (1)

File organization, Define File organization''s and it''s types

Define File organization''s and it''s types

File organisation, File organisation might be described as a method of stor...

File organisation might be described as a method of storing records in file. Also, the subsequent implications approaching these records can be accessed. Given are the factors invo

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

how multiple stacks can be implemented using one dimensional array

What is keyed access- container, What is Keyed Access- Container A c...

What is Keyed Access- Container A collection may allow its elements to be accessed by keys. For instance, maps are unstructured containers which allows their elements to be

Algorithm for determining strongly connected components, Algorithm for dete...

Algorithm for determining strongly connected components of a Graph: Strongly Connected Components (G) where d[u] = discovery time of the vertex u throughout DFS , f[u] = f

Algorithms, write short note on algorithms

write short note on algorithms

Design a binary search tree, Binary Search Tree usage: Write a progra...

Binary Search Tree usage: Write a program to compare the time taken for a search in a skewed tree, a balanced tree, and a random tree. Speci cally, your program should do the

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