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

Representation of data structure in memory, Representation of data structur...

Representation of data structure in memory is known as: Abstract data type

Determine the class invariants- ruby, Determine the class invariants- Ruby ...

Determine the class invariants- Ruby Ruby has many predefined exceptions classes (like ArgumentError) and new ones can be created easily by sub-classing StandardError, so it's

Link list, algorithm for multiplication of two sparse matrices using link l...

algorithm for multiplication of two sparse matrices using link list

Write down the algorithm of quick sort, Write down the algorithm of quick s...

Write down the algorithm of quick sort. An algorithm for quick sort: void quicksort ( int a[ ], int lower, int upper ) {  int i ;  if ( upper > lower ) {   i = split ( a,

Rooted tree, It does not have any cycles (circuits, or closed paths), which...

It does not have any cycles (circuits, or closed paths), which would imply the existence of more than one path among two nodes. It is the most general kind of tree, and might be co

Write down a module to merge two linked lists, Two linked lists are having ...

Two linked lists are having information of the same type in ascending order. Write down a module to merge them to a single linked list that is sorted merge(struct node *p, stru

Name the five popular hashing functions, Five popular hashing functions are...

Five popular hashing functions are as follows: 1) Division Method 2) Midsquare Method 3) Folding Method 4) Multiplicative method 5) Digit Analysis

Programs, Develop a program that accepts the car registration( hint: LEA 43...

Develop a program that accepts the car registration( hint: LEA 43242010)

State z-buffer algorithm, Z-Buffer Algorithm Also known as the Depth-Bu...

Z-Buffer Algorithm Also known as the Depth-Buffer algorithm, this image-space method simply selects for  display the polygon or portion of a polygon that is nearest to the view

Sequential search of a list is preferred over binary search, What are the c...

What are the conditions under which sequential search of a list is preferred over binary search? Sequential Search is a preferred over binary search when the list is unordered

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