insertion and deletion functions in c++

please give me feedback on :)
https://www.facebook.com/invigorating.arslaan

#include <iostream>
using namespace std;


int insertArray(int , int  , int & ,int &);
int DeleteFromArray(int ,int , int &, int &);

int insertArray(int array[], int size, int & no_el,int &new_el)
{


               
cout<<"Enter the position at which you want to insert : ";
                int pos;
                cin>>pos;
                for(int i=no_el-1;i>=pos;i--)
                    array[i+1]=array[i];
                array[pos]=new_el;
                no_el++;


return (0);
}



int DeleteFromArray(int array[],int size, int &key, int &no_el)
{

int pos;
cout<<"enter the position"<<endl;
                cin>>pos;
                for(pos=0;pos<no_el;pos++)
                {
                    if(array[pos]==key)
break;
                       
               
                if(pos==no_el)
                {
                    cout<<"Search key not found";
                    break;
                }
}
                for(int i=pos;i<no_el;i++)
                    array[i]=array[i+1];
                no_el--;
return 0;

}
int main()
{
const int size=15;
int array[size];
    int no_el;
int newelement;
    cout<<"Enter the no of element :";
    cin>>no_el;
cout<<"Enter the new element : ";
cin>>newelement;
cout<<"Enter the value to be search : ";
                int key;
                cin>>key;
    for(int i=0;i<no_el;i++)
    {
        cout<<"Enter the element : ";
        cin>>array[i];
}
insertArray(array, size ,no_el,newelement);
for(int i=0;i<no_el;i++)
{
cout<<"new array is "<<endl;
cout<<array[i]<<" ";
}
cout<<"now for deletion "<<endl;

DeleteFromArray( array, size , key, no_el);

for (int i=0 ;i<no_el;i++)
{
cout<<array[i];
}

system("pause");
return 0;
}


Comments

Popular Posts