Showing posts with label linked list-simple-program-in-c. Show all posts
Showing posts with label linked list-simple-program-in-c. Show all posts

Monday, 28 April 2014

array implementation of list in c

Program Code:-
#include<stdio.h>
#include<conio.h>
void main()
{
  int arr[100],n,i,elements,pos,temps,temp; //Initializing variables and temp variables
  printf("######Implementing Linked List Using Arrays########\n");
  puts("how many elements you have to append\n");
  scanf("%d",&n);//recieve inputs to insert in to list
   for(i=0;i<=n;i++)
   {
  printf(" the element for position is %d\t",i);
  scanf("%d",&arr[i]);//recieve inputs for positions
 }
          for(i=0;i<=n;i++)
   {
  printf(" the element for this  %d position is %d \n",i,arr[i]); //Printing the elements with positions
 }
          printf("#######Implementing Search##########################\n");
          printf("Enter the element to search \n ");
          scanf("%d",&elements);
          for(i=0;i<=n;i++)//Loop to search entire array
   {
     if(arr[i]==elements)
                  {
                    printf("this element %d was found at position %d",elements,i);
                    break;
                    }
              else
                  {
                       //Do nothing
                  }
 }
printf("#######Implementing Insertion by shifting##########################\n");
       printf("Enter the element to insert \n ");
       scanf("%d",&elements);
       printf("Enter the position where to insert \n ");
       scanf("%d",&pos);
       for(i=10;i>=pos-1;i--)
   {
             arr[i+1]=arr[i];
             arr[pos-1]=elements;    
 }

 for(i=0;i<=n;i++)
   {
  printf(" the element for this  %d position is %d \n",i,arr[i]);
 }
}

 

  If you want to delete an element in an array then you shift the positions in a way opposite to previous one so the element of an array is deleted .
sorting algorithm will be updated shortly..I believe not in mixing concepts and i follow divide and concur approach have a nice day guys...