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

Evaluation of arithmetic expressions, Stacks are often used in evaluation o...

Stacks are often used in evaluation of arithmetic expressions. An arithmetic expression contains operands & operators. Polish notations are evaluated through stacks. Conversions of

Data mining assignment, The assignment aims at consolidating your knowledge...

The assignment aims at consolidating your knowledge on data mining techniques and developing practical skills through solving a problem of transcription factor binding sites recogn

Algorithm to build a binary tree , Q. Give the algorithm to build a binary ...

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

Representation of linked list in memory, Representation of Linked list in M...

Representation of Linked list in Memory:- Each node has an info part and a pointer to the next node also known as link. The number of pointers is two in case of doubly linked

Sparse matrix, what are the disadvantages of sparse matrix?

what are the disadvantages of sparse matrix?

Draw a flowchart to input start time and end time of vehicle, Speed cameras...

Speed cameras read the time a vehicle passes a point (A) on road and then reads time it passes a second point (B) on the same road (points A and B are 100 metres apart). Speed of t

Algorithm, Write an algorithm for compound interest.

Write an algorithm for compound interest.

Graphs, floyd warshall algorithm

floyd warshall algorithm

Write the algorithm of the quick sort, Ans. An algorithm for the quick...

Ans. An algorithm for the quick sort is as follows: void quicksort ( int a[ ], int lower, int upper ) { int i ; if ( upper > lower ) { i = split ( a, lower, up

Stack, Explain in detail the algorithmic implementation of multiple stacks....

Explain in detail the algorithmic implementation of multiple stacks.

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