Sie sind auf Seite 1von 5

#include<iostream.

h>

#include<process.h>

#include<conio.h>

#include<stdio.h>

int n=20;

void insert(char a[], char el,int& n)

if(n>=20)

cout<<"\n\n overflow\n" ;

exit(0);

int pos;

if(el < a[0]) pos =0;

else

for(int i=0; i<n-1;i++)

if(a[i]<el && el<a[i+1])

pos = i+1;

break;

cout<<"\n\n";

if(i==n-1) pos =n;


cout<<"\nposition of it is "<<pos;

char tmp;

for(int m =n-1;m>=pos;m--)

a[m+1]=a[m];

a[pos] = el;

n+=1;

cout<<"\n\n";

for(int t=0; t<n;t++)

cout<<"\t"<<a[t]<<"\t";

return;

void del(char a[], char el,int& n)

if(n==0)

cout<<"\nunderflow \n";

exit(0);

int i=0;
for(;i<n;i++)

if(a[i]==el)

break;

if(i ==n-1)

if(a[n-1]!=el)

cout<<"\nelement not found\n";

return;

for(int j=i;j<n;j++)

a[j] = a[j+1];

n-=1;

cout<<"\n\n";

for(int k =0; k<n;k++)

cout<<"\t"<<a[k]<<"\t";

return;

void main()
{

clrscr();

char a[20],el;

int ch;

char rep ='y';

cout<<"\n enter the number of elements \n ";

cin>>n;

cout<<"\n Enter the values asc \n";

for(int i=0;i<n;i++)

cin>>a[i];

while(rep =='y')

cout<<"\n choose the following \n 1.insertion \n 2. deletion \n 3. exit \n";

cin>>ch;

if(ch==1)

cout<<"\n element to be inserted \t";

cin>>el;

insert(a,el,n);

if(ch==2)

cout<<"\n element to be deleted\n";

cin>>el;

del(a,el,n);
}

if(ch==3)

exit(0);

cout<<"\nenter y to continue\n";

cin>>rep;

getch();

Das könnte Ihnen auch gefallen