Thursday, 18 July 2013

Algorithm for Deletion in One Dimensional Array

  1. Set item= a[pos]
  2. Repeat for j=pos to n-1[Shifting elements one position upwards]Set a[j]=a[j+1][End of loop]
  3. Reset n=n-1
  4. Display the new list of element
  5. End

1 comment:

  1. void deletion(int pos,int currsize,int item)
    {
    item=A[pos];
    for(int i=pos;i<currsize-1;i++)
    A[i]=A[i+1];
    currsize--;
    cout<<"updated array"<<endl;
    for(int i=0;i<=currsize;i++)
    cout<<"element at position "<<i+1<<" is "<<A[i]<<endl;
    } //output is not coming correctly

    ReplyDelete