INSERTION IN LINKED LIST AT DIFFERENT POSITION

THIS PROGRAM IS TESTED IN DEV C++

#include<stdio.h>
#include<conio.h>
void insert1()
{
   int array[100], position, c, n, value;
   printf("Enter number of elements in array\n");
   scanf("%d", &n);
   printf("Enter %d elements\n", n);
   for (c = 0; c < n; c++)
      scanf("%d", &array[c]);
   printf("Enter the location where you wish to insert an element\n");
   scanf("%d", &position);
   printf("Enter the value to insert\n");
   scanf("%d", &value);
   for (c = n; c >= position; c--)
      array[c+1] = array[c];
    array[position] = value;
   printf("Resultant array is\n");
   for (c = 0; c <= n; c++)
      printf("%d\n", array[c]);
}
    void insert2()
{
   int array[100], position=0, c, n, value;
   printf("Enter number of elements in array\n");
   scanf("%d", &n);
   printf("Enter %d elements\n", n);
   for (c = 0; c < n; c++)
      scanf("%d", &array[c]);
   printf("Enter the value to insert\n");
   scanf("%d", &value);
   for (c = n; c >= position; c--)
      array[c+1] = array[c];
   array[position] = value;
   printf("Resultant array is\n");
   for (c = 0; c <= n; c++)
      printf("%d\n", array[c]);
}
    void insert3()
{
   int array[100], position, c, n, value;
  printf("Enter number of elements in array\n");
   scanf("%d", &n);
   printf("Enter %d elements\n", n);
   for (c = 0; c < n; c++)
      scanf("%d", &array[c]);
   printf("Enter the value to insert\n");
   scanf("%d", &value);
 array[n] = value;
 n=n+1;
   printf("Resultant array is\n");
 for (c = 0; c < n; c++)
      printf("%d\n", array[c]);
}
int main()
{
while(1){
        int m;
    printf("1.Enter 1 to insert at the k position \n");
    printf("2.Enter 2 to insert at the start\n");
    printf("3.Enter 3 to insert at the end\n");
    scanf("%d",&m);
    switch(m)
    {
    case 1:
            insert1();
            break;
            case 2:
            insert2();
            break;
            case 3:
            insert3();
            break;
    }
return 0;
}
}
linked list

Previous
Next Post »

ConversionConversion EmoticonEmoticon

:)
:(
=(
^_^
:D
=D
=)D
|o|
@@,
;)
:-bd
:-d
:p
:ng