Program of insertion of an element in list, Data Structure & Algorithms

Assignment Help:

Program will demonstrate the insertion of an element at desired position

/* Inserting an element into contiguous list (Linear Array) at particular position */

/* contiguous_list.C */

# include

/* definition of linear list */

typedefstruct

{

}list;

int data[10];

int count;

/*prototypes of functions */ void insert(list *, int, int); void create(list *);

 

void traverse(list *);

/* Definition of the insert funtion */

void insert(list *start, int position, int element)

{

int temp = start->count;

while( temp >= position)

{

start->data[temp+1] = start->data[temp];

temp --;

}

start->data[position] = element;

start->count++ ;

}

/* definition of the create function to READ data values in the list */

void create(list *start)

{

inti=0, test=1;

while(test)

{

fflush(stdin);

printf("\n input value for: %d:(zero to come out) ", i);

scanf("%d", &start->data[i]);

if(start->data[i] == 0)

test=0;

else

}

i++;

start->count=i;

}

/* OUTPUT FUNCTION TO PRINT ON THE CONSOLE */

void traverse(list *start)

{

inti;

for(i = 0; i< start->count; i++)

{

printf("\n Value at the position: %d: %d ", i, start->data[i]);

}

}

/* main function */

void main( )

{

int position, element;

list l;

create(&l);

printf("\n Entered list as:\n");

fflush(stdin);

traverse(&l);

fflush(stdin);

printf("\n input the position where youdesire to insert new item:");

scanf("%d", &position);

fflush(stdin);

printf("\n input value for desired position:");

scanf("%d", &element); insert(&l, position, element); traverse(&l);

}


Related Discussions:- Program of insertion of an element in list

Sparse matrix, How sparse matrix stored in the memory of a computer?

How sparse matrix stored in the memory of a computer?

Numerical - algorithm, Q. What is the smallest value of n such that an algo...

Q. What is the smallest value of n such that an algorithm whose running time is 100n2 runs faster than an algorithm whose running time is 2n on the same machine.    A n

Characteristics of good algorithms, What do we mean by algorithm? What are ...

What do we mean by algorithm? What are the characteristics of a good and relevant algorithm? An algorithm is "a step-by-step procedure for finishing some task'' An algorithm c

Two sparce matrices multipilcation algorithm, Write an algorithm for multi...

Write an algorithm for multiplication of two sparse matrices using Linked Lists.

Physical database design and sql queries, In this part, students are allowe...

In this part, students are allowed to implement the following simplifications in their table and data design. o Availability for the beauty therapists don't have to be considere

Boundary tag method in context of dynamic memory management, Q. How can we ...

Q. How can we free the memory by using Boundary tag method in the context of Dynamic memory management?

Dynamic programming., Count Scorecards(30 points) In a tournament, N playe...

Count Scorecards(30 points) In a tournament, N players play against each other exactly once. Each game results in either of the player winning. There are no ties. You have given a

Add the special form let to the metacircular interpreter, (1)  (i) Add the ...

(1)  (i) Add the special form let to the metacircular interpreter Hint: remember let is just syntactic sugar for a lambda expression and so a rewrite to the lambda form is all t

Which is the most suitable data type, Problem 1. You are asked to store...

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

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