مستند نصي جديد2222

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

#include<iostream>

#include<conio.h>
using namespace std;
struct nodee{
int item;
nodee *nextt;};
nodee *firstt,*lastt;
int count;
void add_first(int aa)
{nodee *dnodee=new nodee;
dnodee->item=aa;
if (count==0)
{firstt=lastt=dnodee;
dnodee->nextt=NULL;}
else
{dnodee->nextt=firstt;
firstt=dnodee;
}
count++;
}
void add_last(int a2)
{nodee *dnodee=new nodee;
dnodee->item=a2;
if (count==0)
{firstt=lastt=dnodee;
dnodee->nextt=NULL;}

else {
lastt->nextt=dnodee;
dnodee->nextt=NULL;
lastt=dnodee;
}
count ++;}
void add_medall(int b,int a3)
{if (b<0 || b>count)
cout<<"not found";
else
{nodee *dnodee=new nodee;
dnodee->item=a3;
if(b==0)
add_first(a3);
else if(b==count)
add_last(a3);
else {nodee *cur=firstt;
for(int i=1;i<b;i++)
{cur=cur->nextt;
}
dnodee->nextt=cur->nextt;
cur->nextt=dnodee;
count++;}}}
void disply()
{nodee *cur1=firstt;
while(cur1!=NULL)
{cout<<cur1->item<<" ";
cur1=cur1->nextt;
}
}
void remove_first()
{if(count==0)
return;
else if(count==1)
{
delete firstt;
lastt=firstt=NULL;
count--;}
else{
nodee *cur=firstt;
firstt=firstt->nextt;
delete cur;
count--;
}
}
void remove_last()
{if(count==0)
return;
else if(count==1)
{
delete firstt;
lastt=firstt=NULL;
count--;}
else{
nodee *cur=firstt->nextt;
nodee *prf=firstt;
while(cur!=lastt)
{prf=cur;cur=cur->nextt;}
delete cur;
prf->nextt=NULL;
lastt=prf;
count--;}
}
void remove_medall(int m)
{if(count==0)
return;
nodee *cur,*prf;
if(firstt->item==m)
{cur=firstt; firstt=firstt->nextt;
delete cur; count --;
if (count==0)
lastt=NULL;}
else{
cur=firstt->nextt;
prf=firstt;
while(cur!=NULL)
{if(cur->item==m)
break;
prf=cur;
cur=cur->nextt;
}
if(cur==NULL)
cout<<"not fond";
else {prf->nextt=cur->nextt;
if(lastt==cur)
lastt=prf;
delete cur;
count --;
} }}
int mm,m1,m2,m3,m4,m5,m6;

case 4:cout<<" \n HELLO IN SINGEL LINK \n";


cout<<" \n inter how many number you want to
insert to add_first \n";
cin>>mm;
cout<<" \nenter numbers \n";
for(int i=1;i<=mm;i++){
cin>>m1;
add_first(m1);}disply();
cout<<" \ninter how many number you want to insert to add_last \n";
cin>>m2;
cout<<" \nenter numbers \n";
for(int i=1;i<=m2;i++){
cin>>m3;
add_last(m3);}disply();
cout<<" \ninter how many number you want to insert to add_medall \n";
cin>>m4;
cout<<" \nenter numbers \n";
for(int i=1;i<=m4;i++){
cin>>m5;
add_medall(1,m5);}
disply();
cout<<"\n";
cout<<"\n the link list after delete in the last: \n";
remove_last();disply();
cout<<"\n the link list after delete in the firest: \n";
remove_first();disply();
cout<<"\n enter the number you want to delete in the medel: \n";
cin>>m6;
remove_medall(m6);
disply();
break;
case -10:
cout<<"good bay";
exit(0);
break;
}
}
getch();
return 0;
}

You might also like