SHARE
TWEET

File

a guest Dec 3rd, 2019 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include <windows.h>
  3. using namespace std;
  4. int pil;
  5. void pilih();
  6. void hapusdata();
  7. void buat_baru();
  8. void tambah_depan();
  9. void hapus_depan();
  10. void tampil();
  11. struct node
  12. {
  13.  char angka[13];
  14.  string nama;
  15.  string alamat;
  16.     node *prev, *next;
  17. };
  18. node *baru, *head=NULL, *tail=NULL,*hapus,*bantu,*bantu2;
  19. int main(){
  20. do{
  21. system("cls");
  22. cout<<"SELAMAT DATANG DI E-BUKTEL "<<endl;
  23. cout<<"=========================\n";
  24. cout<<"1. Tamabah Kontak"<<endl;
  25. cout<<"2. Hapus Kontak"<<endl;
  26. cout<<"3. lihat kontak"<<endl;
  27. cout<<"4. Keluar"<<endl;
  28. cout<<"Pilihan : ";cin>>pil;
  29. pilih();
  30. }
  31. while(pil!=4);
  32. }
  33. void pilih(){
  34.     if(pil==1)
  35.         tambah_depan();
  36.     else if(pil==2)
  37.         hapus_depan();
  38.     else if(pil==3)
  39.         tampil();
  40.     else
  41.         cout<<"selesai";
  42.     }
  43. void buat_baru(){
  44.     baru =new(node);
  45.  cin.ignore();
  46.  cout<<"\nMasukkan Nama\t: ";
  47.  getline(cin,baru->nama);
  48.  cout<<"Masukkan Alamat\t: ";
  49.  getline(cin,baru->alamat);
  50. cout<<"Masukkan No HP   : ";cin>>baru->angka;
  51.     baru->prev=NULL;
  52.     baru->next=NULL;
  53.     }
  54.  
  55.     void tambah_depan(){
  56.     buat_baru();
  57.     if(head==NULL){
  58.     head=baru;
  59.     tail=baru;
  60.     }
  61.     else{
  62.     baru->next=head;
  63.     head->prev=baru;
  64.     head=baru;
  65.     }
  66.     cout<<endl;
  67.     tampil();
  68.     }
  69.  
  70. void hapus_depan() {
  71.     if (head==NULL)
  72.     cout<<"Kosong";
  73.     else if(head->next==NULL){
  74.         hapus=head;
  75.         head=NULL;
  76.         tail=NULL;
  77.         delete hapus;
  78.     }
  79.     else {
  80.         hapus=head;
  81.         head=hapus->next;
  82.         head->prev=NULL;
  83.         delete hapus;
  84.     }
  85.     cout<<endl<<endl;
  86.     tampil();
  87. }
  88.  
  89.  
  90. void tampil(){
  91.     if (head==NULL)
  92.     cout<<"Kosong\n";
  93.     else {
  94.     bantu=head;
  95.     int no=0;
  96.     while(bantu!=NULL){
  97.     no++;
  98.     cout<<"Kode     : ";cout<<" "<<no<<" "<<endl;
  99.     cout<<"Nama     : ";cout<<bantu->nama<<endl;
  100.     cout<<"alamat       : ";cout<<bantu->alamat<<endl;
  101.     cout<<"No.Hp        : ";cout<<bantu->angka<<endl;
  102.  
  103.     cout<<"==================="<<endl;
  104.     bantu=bantu->next;
  105.     }
  106.     }system("pause");
  107.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top