Mailian_Blogger

Algoritma Program Single Link List

Dec 10th, 2018 (edited)
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.58 KB | None | 0 0
  1. /***************************************
  2. Created     : Satria Mailian Gumelar
  3. Algoritma   : Single Link List
  4. Mata Kuliah : Struktur Data
  5. Kampus      : Univesitas Pamulang
  6. Website     : www.mailianblogger.com
  7. ***************************************/
  8. #include <iostream>
  9. #include <conio.h>
  10. #include <iomanip>
  11. #include <stdlib.h>
  12. using namespace std;
  13.  
  14. void Inisialisasi();
  15. void Input_SMG();
  16. void Hapus_SMG();
  17. void Cetak_SMG();
  18. void Menu_SMG();
  19.  
  20. struct node
  21. {
  22.     int data;
  23.     node* next;
  24. };
  25.     node* head;
  26.     node* tail;
  27.     node* curr;
  28.     node* entry;
  29.     node* del;
  30.    
  31. void Inisialisasi()
  32.     {
  33.         head = NULL;
  34.         tail = NULL;
  35.     }
  36.  
  37. void Input_SMG(int dt)
  38.     {
  39.         entry = (node* )malloc(sizeof(node));
  40.         entry->data = dt;
  41.         entry->next = NULL;
  42.         if(head==NULL)
  43.     {
  44.         head = entry;
  45.         tail = head;
  46.     }
  47.         else
  48.     {
  49.         tail->next = entry;
  50.         tail = entry;
  51.         }
  52.     }
  53. void Hapus_SMG()
  54.     {
  55.         int simpan;
  56.         if(head==NULL)
  57.     {
  58.         cout<<"Linked List Kosong"<<endl;
  59.     }
  60.         else
  61.     {
  62.         simpan = head ->data;
  63.         cout<<"Data diHapus -> "<<simpan<<endl;
  64.         del = head;
  65.         head = head->next;
  66.         delete del;
  67.     }
  68. }
  69.  
  70. void Cetak_SMG()
  71.     {
  72.         curr = head;
  73.         if(head == NULL)
  74.         cout<<"Tidak Ada Data"<<endl;
  75.         else
  76.     {
  77.         cout<<"Data Linked List : ";
  78.         cout<<setw(6);
  79.         while(curr!=NULL)
  80.     {
  81.         cout<<curr->data<<"->";
  82.         curr = curr->next;
  83.     }
  84.         cout<<endl;
  85.         }
  86.     }
  87.  
  88. void Menu_SMG()
  89.     {
  90.         char pilih, ulang;
  91.         int data;
  92.         do
  93.     {
  94.         system("cls");
  95.         cout<<"******************************************"<<endl;
  96.         cout<<"Nama        : Satria Mailian Gumelar"<<endl;
  97.         cout<<"NIK         : 171011400077"<<endl;
  98.         cout<<"Dosen       : Bodi Santoso"<<endl;
  99.         cout<<"Mata Kuliah : Struktur Data"<<endl;
  100.         cout<<"Website     : www.mailianblogger.com"<<endl;
  101.         cout<<"******************************************"<<endl;
  102.         cout<<"\t     Single Link List"<<endl;
  103.         cout<<"******************************************"<<endl;
  104.         cout<<"\t       Pilihan Anda"<<endl;
  105.         cout<<"\t1. Input Data\t2. Hapus Data"<<endl;
  106.         cout<<"\t3. Cetak Data\t4. Exit"<<endl;
  107.         cout<<"******************************************"<<endl;      
  108.         cout<<"Masukan Pilihan Anda : ";
  109.         cin>>pilih;
  110.         switch(pilih)
  111.     {
  112.         case '1' :
  113.         cout<<"Masukkan Data : ";
  114.         cin>>data;
  115.         Input_SMG(data);
  116.         break;
  117.  
  118.         case '2' :
  119.         Hapus_SMG();
  120.         break;
  121.  
  122.         case '3' :
  123.         Cetak_SMG();
  124.         break;
  125.  
  126.         case '4' :
  127.         exit(0);
  128.         break;
  129.         default :
  130.         cout<<"\t   Pilihan Anda Salah!"<<endl;
  131.     }
  132.         cout<<"\nLanjutkan ke Menu ?(y/n)";
  133.         cin>>ulang;
  134.     }
  135.         while(ulang=='y' || ulang=='Y');
  136.     }
  137.  
  138. int main()
  139.     {
  140.         Inisialisasi();
  141.         Menu_SMG();
  142.         return EXIT_SUCCESS;
  143. }
Add Comment
Please, Sign In to add comment