iseqai

Untitled

Sep 29th, 2020 (edited)
1,288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <windows.h>
  5. using namespace std;
  6.  
  7. int pilih; void pilihan();
  8.  
  9. struct SIMPUL{
  10.  char nim[20];
  11.  char nama [40];
  12.  char gender [20];
  13.  int info;
  14.  float nilai;
  15.  SIMPUL *prev, *next;
  16. };
  17.  
  18. SIMPUL *data, *front=NULL, *rear=NULL,*help,*del, *q;
  19.  
  20. void BUAT_SIMPUL(int X)
  21. {
  22. data=(SIMPUL *)malloc(sizeof(SIMPUL));
  23. if(data!=NULL)
  24. data->info=X;
  25. else
  26. {
  27. cout<<"Membuat simpul gagal";
  28. exit(1);
  29. }
  30. }
  31.  
  32. void buat_data()//fungsi membuat data data
  33. {
  34.  data = new(SIMPUL);
  35.  cout<<"    Masukkan Nama : ";cin>>data->nama;
  36.  cout<<"    Masukkan NIM : ";cin>>data->nim;
  37.  cout<<"    Masukkan Gender : ";cin>>data->gender;
  38.  cout<<"    Masukkan Nilai : ";cin>>data->nilai;
  39.  cout<<"\n  ==========================";
  40.  cout<<"\n    Data telah dimasukkan   ";
  41.  getch();
  42.   data->prev=NULL;
  43.  data->next=NULL;
  44. }
  45.  
  46. void insert_data()
  47. {
  48.  buat_data();
  49.  if(front==NULL)
  50.  {
  51.   front=data;
  52.   rear=data;
  53.   rear->next=NULL;
  54.  }
  55.  else
  56.  {
  57.  
  58.   rear->next=data;
  59.   rear=data;
  60.   rear->next=NULL;
  61.  }
  62.  cout<<endl<<endl;
  63. }
  64.  
  65. void hapus_data()//fungsi penghapusan data
  66. {
  67.  int hapus;
  68.  if(front==NULL)
  69.  {
  70.   cout<<"   stack  kosong"<<endl;
  71.   getch();
  72.  }
  73.  else
  74.  {
  75.   hapus=front->info;
  76.   cout<<"   Data awal sudah dihapus";
  77.   del = front;
  78.   q = front->next;
  79.   front=q;
  80.   delete del;
  81.   getch();
  82.  }
  83. }
  84.  
  85. void cetak_data()
  86. {
  87.  if (rear==NULL){
  88.  cout<<"    Linked List kosong!";
  89.  getch();
  90.  }
  91.  else
  92.  {
  93.   help=front;
  94.   while(help!=NULL)
  95.   {
  96.    cout<<"  Nama : "<<help->nama<<endl;
  97.    cout<<"  NIM : "<<help->nim<<endl;//data akan muncul dengan tampilan
  98.    cout<<"  Gender : "<<help->gender<<endl;
  99.    cout<<"  Nilai : "<<help->nilai<<endl;
  100.    cout<<endl;
  101.    help=help->next;
  102.  
  103.  }
  104. getch();
  105.  
  106. }
  107. }
  108.  
  109. int main()//interface monitor
  110. {
  111.  do
  112.  {
  113.   system("cls");   
  114.   cout<<"   STACK LINKED LIST WITH HEAD"<<endl;
  115.   cout<<"   ============================="<<endl;
  116.   cout<<"   1. INSERT DATA"<<endl;
  117.   cout<<"   2. HAPUS DATA"<<endl;
  118.   cout<<"   3. CETAK DATA"<<endl;
  119.   cout<<"   4. EXIT"<<endl;
  120.   cout<<"   ============================="<<endl;
  121.   cout<<"   Pilihan : ";
  122.   cin>>pilih;
  123.   cout<<"   ============================="<<endl;
  124.   cout<<endl;
  125.   pilihan();
  126.  }
  127.  
  128.  while(pilih!=4);
  129. }
  130.     void pilihan()//fungsi "pilihan" untuk pemrosesan
  131.     {
  132.     if(pilih==1){
  133.      insert_data();}
  134.  
  135.     else if(pilih==2)
  136.        hapus_data();
  137.        
  138.     else if(pilih==3)
  139.        cetak_data();
  140.        
  141.     else
  142.      {
  143.      cout<<"    Terima kasih sudah menggunakan program ini"<<endl;
  144.       }
  145.     }
Advertisement
Add Comment
Please, Sign In to add comment