Tam kodu atarmisin knkm düzenler atarım
#include<iostream>
using namespace std;
int insert();
int list();
int find();
int delet();
struct node
{
int sayi;
node *adres;
};
node *head=NULL;
int main()
{
setlocale(LC_ALL,"TURKISH");
int menu;
bool var = true;
while(var)
{
cout<<"Listeye sayı eklemek için 1'e basın"<<endl;
cout<<"Listedeki sayıları görüntülemek için 2'e basın "<<endl;
cout<<"Listede herhangi bir sayının olup olmadığını kontrol etmek için 3'e basın"<<endl;
cout<<"Listeden sayı silmek için 4'e basın "<<endl;
cout<<"Programdan çıkış yapmak için 5'e basın "<<endl;
cin>>menu;
switch(menu)
{
case 1:
insert();
break;
case 2:
list();
break;
case 3:
find();
break;
case 4:
delet();
break;
case 5:
return 0;
break;
default:
{
cout<<"Lütfen menü dışı bir sayı girmeyiniz"<<endl;
cout<<endl;
return main();
}
}
}
return 0;
}
int insert()
{ node *yenidugum=new node();
cout<<"Lütfen bir sayı giriniz"<<endl;
cin>>yenidugum->sayi;
cout<<endl;
if(head==NULL)
{
head=yenidugum;
}
else
{
yenidugum->adres=head;
head=yenidugum;
}
}
int list()
{
if(head==NULL)
{
cout<<"Listede sayı bulunmuyor"<<endl;
cout<<endl;
return 0;
}
else
{
node *listele=head;
cout<<"Listedeki sayılar"<<endl;
while(listele!=NULL)
{
cout<<listele->sayi<<"\t";
listele=listele->adres;
}
cout<<endl<<endl;
}
}
int find()
{
if(head==NULL)
{
cout<<"Listede sayı bulunmuyor"<<endl;
cout<<endl;
return 0;
}
else
{
int istenen;
node *find=head;
cout<<"Bulunmasını istediğiniz sayıyı girin"<<endl;
cin>>istenen;
while(find!=NULL)
{
if(find->sayi==istenen)
{
cout<<istenen<<" sayısı bulundu"<<endl;
cout<<endl;
break;
}
else
{
find=find->adres;
}
}
}
}
int delet()
{
if(head==NULL)
{
cout<<"Liste boş ,silme işlemi yapılamıyor"<<endl;
cout<<endl;
return 0;
}
else
{
int sil;
cout<<"Lütfen silinmesini istediğiniz sayıyı giriniz"<<endl;
cin>>sil;
if(head->sayi==sil)
{ node *silinecek=head;
cout<<sil<<" değeri sayılardan silindi"<<endl;
head=head->adres;
delete silinecek;
}
else
{
node *currentnode=head->adres;
node *prevnode=head;
while(currentnode!=NULL)
{
if(currentnode->sayi==sil)
{
node *silinecek=currentnode;
prevnode->adres=currentnode->adres;
cout<<sil<<" değeri listeden silindi"<<endl;
delete silinecek;
break;
}
else
{
currentnode=currentnode->adres;
prevnode=prevnode->adres;
}
}
}
}
}