logow

C PROGRAM TO INSERT ELEMENT IN ANY SPECIFIC POSITION DATA STRUCTURES

HELLO WELCOME TO THIS C-basics BLOG...........

C PROGRAM ME AAJ HUM ARRAY ME DATA INSERT KARNA SIKHENGE WO BHI KISI BHI POSITION PE......

STEPS::
ALGORITHM AND BASIC OPERATIONS ON ARRAY --

Basic Operations

Following are the basic operations supported by an array.
              Traverse − print all the array elements one by one.
  • Insertion − Adds an element at the given index.
  • Deletion − Deletes an element at the given index.
  • Search − Searches an element using the given index or by the value.
  • Update − Updates an element at the given index.


  • Array in C
    Insertion In Array 
    1.) The first element in the array is assumed to be sorted. Take the second element and store it separately in KEY.

    Compare key with the first element. If the first element is greater than key, then key is placed in front of the first elemet.

 2.) Now, the first two elements are sorted.

Take the third element and compare it with the elements on the left of it. Placed it just behind the element smaller than it. If there is no element smaller than it, then place it at the beginning of the array.


#include<stdio.h>
#include<conio.h>  // these are header files for pre-defined functions
int main()
 // main function 
{
int array[100],no,i,value,position;
printf("enter the size of array:::::\n");
scanf("%d",&no);
printf("enter the elements in given size of aray:::::\n");
for(i=0;i<=no-1;i++)
{
scanf("%d",&array[i]);

}

printf("your given elements are::::\n");
for(i=0;i<=no-1;i++)
{
printf("%d\n",array[i]);

}
printf("enter the specific position do you want to insert::::\n");
scanf("%d",&position);
printf("enter the value do you want to insert::::\n");
scanf("%d",&value);
for(i=no-1;i>=position;i--)
{
array[i+1] = array[i];
array[position] = value;
}
printf("updated array are::::::\n");
for(i=0;i<=no;i++)
{
printf("%d\n",array[i]);

}
}

OUTPUT AAPKA SHOW HOGA ........


C Program
Output of Array Program 



SO THANK YOU AAJ KE LIYE ETNA HI MILTE HAI NEXT POST ARRAY DATA DELETION KE SAATH .....................



Post a Comment

0 Comments