#pragma hdrstop
#include <iostream.h>
#include <conio.h>
//---------------------------------------------------------------------------
#pragma argsused
struct list{
int info;
list *next;
};
list *first;
list *last;
list *p;
list *prec;
int main(int argc, char* argv[])
{
int pilih;
do{
cout<<"Menu Operasi List: "<<endl;
cout<<"1. Create List"<<endl;
cout<<"2. Insert Element Pertama"<<endl;
cout<<"3. Insert First"<<endl;
cout<<"4. Insert Last"<<endl;
cout<<"5. Insert After"<<endl;
cout<<"6. Delete First"<<endl;
cout<<"7. Delete After"<<endl;
cout<<"8. Delete Last"<<endl;
cout<<"9. Tampilkan List"<<endl;
cout<<"0. Keluar"<<endl;
cout<<"Masukan Pilihan Anda: ";
cin>>pilih;
switch(pilih){
case 1 :
{ first = NULL;
last = NULL;
cout<<"List Created!"<<endl;
break;
}
case 2 :
{ list *p = new list();
cout<<"Masukkan nilai list: ";
cin>>p->info;
p->next=NULL;
first = p;
last = p;
break;
}
case 3 :
{ list *p = new list();
cout<<"Masukkan list first: ";
cin>>p->info;
p->next = first;
last = first;
first = p;
break;
}
case 4 :
{ list *p = new list();
cout<<"Masukkan list last: ";
cin>>p->info;
last->next = p;
p->next = NULL;
last = p;
break;
}
case 5 :
{ int x,y;
list *p = new list();
cout<<"Masukkan nilai insert after: ";
cin>>x;
cout<<"Masukkan setelah angka: ";
cin>>y;
prec = first;
while (prec!=NULL && p->info==y)
{
prec = prec->next;
}
p->info = x;
p->next = prec->next;
prec->next=p;
break;
}
case 9 :
{ p = first;
while (p!=NULL)
{
cout<<p->info<<" ";
p = p->next;
}
break;
}
}
getch();
clrscr();
}while(pilih!=0);
getch();
return 0;
}
//---------------------------------------------------------------------------
No comments:
Post a Comment