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
Problem 1. You are asked to store Names of all 100 students of class A in your Learning Centre. Which data type will you use? What is its syntax? Explaining the data typ

This question is based on the requirements of a system to record band bookings at gigs. (A 'gig' is an event at which one or more bands are booked to play). You do not need to know

Arrays are simple, however reliable to employ in more condition than you can count. Arrays are utilized in those problems while the number of items to be solved out is fixed. They

Define a sparse metrics. A matrix in which number of zero entries are much higher than the number of non zero entries is known as sparse matrix. The natural method of showing m

Q. Give the algorithm to build a binary tree where the yields of preorder and post order traversal are given to us.

Define Strictly Binary Tree Strictly Binary Tree: - If each non leaf node in binary tree has non empty left and right sub-trees , then the tree is known as a strictly binary t

QUESTION Explain the following data structures: (a) List (b) Stack (c) Queues Note : your explanation should consist of the definition, operations and examples.

Q. Write down an algorithm to insert a node in between any two nodes in a linked list         Ans. Insertion of a the node after the given element of the listis as follows

What data structure would you mostly likely see in a nonrecursive execution of a recursive algorithm? Stack