Struktur Antrian Data Dengan Linked List C++

  • Uploaded by: Abdur Rohman M
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Struktur Antrian Data Dengan Linked List C++ as PDF for free.

More details

  • Words: 428
  • Pages: 5
Makefile: jilid: raskin.cpp link01.h g++ -o jilid raskin.cpp

Link01.h: /* Praktikum : LINK list

*/

/* Praktikan mendefinisikan suatu variable global yang bisa dimodifikasi dari dalam suatu fungsi */ /**************************************************/ /* PROTOTYPE */ #define SIZE_CHAR 30 struct link_ptr { struct link_ptr *next; int nmor; char n[SIZE_CHAR],m[SIZE_CHAR],no[8]; };

/* Memeriksa apakah suatu Link kosong? */ extern int is_empty(void); /* Memeriksa apakah suatu Link penuh? */ extern int is_full(void); /* Menambahkan suatu item ke dalam Link */ extern void insert(char *nama,char *merk, int nopol); /* Mengambil suatu item dari dalam Link */ extern void delete_item(void); /* Mencari item*/ extern void search_item(char nopol[8]); /* Mencetak isi Link (dari urutan pertama), jika ada */ extern void print_item(void);

raskin.cpp #include "link01.h" #include //#include //#include using namespace std; struct link_ptr *temp; struct link_ptr *temp2; struct link_ptr *kepala; //void startCurses(); int batas=0; int is_empty() { if (kepala==NULL) return 1; else return 0; } int is_full() { if (batas>4) return 1; else return 0; } void insert(char *ktp,char *nama,char *jatah) { struct link_ptr *baru; baru=(struct link_ptr*)malloc(sizeof(struct link_ptr)); baru->nmor=batas+1; strcpy(baru->n,ktp); strcpy(baru->m,nama); strcpy(baru->no,jatah); if(is_empty()) { baru->next=NULL; kepala=baru; batas++; cout<<"\n!Data berhasil dimasukkan"<<endl; } else { temp=kepala; while(temp->next!=NULL) {

temp=temp->next; } baru->next=NULL; temp->next=baru; batas++; cout<<"\n!Data berhasil dimasukkan"<<endl; } } void search_item(char nopol[8]) { if(is_empty()) { cout<<"\n\a!Belum ada data"<<endl; } else { temp=kepala; int ada=0; int cek=0; while(cek==0) { if(strcmp(temp->no,nopol)==0 || temp->next==NULL) { cek=1; if(strcmp(temp->no,nopol)==0) ada=1; } else temp=temp->next; } if(ada==1) { cout<<"\nNo KTP : "<no; cout<<"\nNama : "<m; cout<<"\nJatah Raskin : "<n<<" kg"<<endl<<endl; } else cout<<"\n\a!Data tidak ditemukan"<<endl; } } void delete_item(void) { temp=kepala; if(is_empty()) cout<<"\n\a!Data kosong"<<endl; else if(temp->next==NULL) { kepala=NULL; cout<<"\n!Data terakhir berhasil dihapus\a"; } else { temp=kepala;

temp2=temp->next; kepala->next=temp2->next; kepala=temp2; cout<<endl<<"\n!Data berhasil dihapus"<<endl; } } void print_item() { if(is_empty()) { cout<<"\n\a!Data kosong"<<endl; } else { temp=kepala; while(temp->next!=NULL) { cout<<endl<nmor<<". "<<"No "<no; cout<<endl<<" Nama : cout<<endl<<" Jatah Raskin : temp=temp->next; } cout<<endl<nmor<<". "<<"No "<no; cout<<endl<<" Nama : cout<<endl<<" Jatah Raskin : temp=temp->next; } }

KTP

:

"<m; "<n<<endl;

KTP

:

"<m; "<n<<endl;

int main() { int p; char name[SIZE_CHAR],type[SIZE_CHAR],number[8]; cout<<"\n\n\n\t\t\tSISTEM ANTRI PEMBAGIAN RASKIN\n"; cout<<"\n\t\t Tugas Jilid Praktikum Struktur Data"; cout<<"\n\n\n\n\n\n\nanggota :"; cout<<"\n - Ridwan"; cout<<"\n - Fn.F"; cout<<"\n - abdurrm"; cout<<"\n - Ahda\n\n\n\n\n"; do { cout<<"\n\t\t\t\t\t\t\t\t [hit enter!]"; getchar(); ~getchar(); system("clear"); cout<<endl<<"Pilihan program :"<<endl; cout<<" 1. Tambah pengantri"<<endl;

cout<<" 2. Bagikan Beras"<<endl; cout<<" 3. Daftar Pengantri"<<endl; cout<<" 4. Cari"<<endl; cout<<" 5. Keluar Program"<<endl; cout<<"Masukkan pilihan :";cin>>p; switch(p) { case 1: cout<<endl<<"Masukkan No KTP ";cin>>number; cout<<"Masukkan Nama : ";cin>>type; cout<<"Masukkan Jatah Raskin : ";cin>>name; insert(name,type,number);break; case 2: delete_item();break; case 3: print_item();break; case 4: cout<<"Masukkan No KTP yang dicari :";cin>>number; search_item(number);break; } } while(p!=5); return 0; }

:

Related Documents

Linked List
November 2019 12
Linked List
May 2020 8
Linked List Notes
November 2019 16
Materi 7 - Linked List
November 2019 19

More Documents from "Euis Marlina"