Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "SLL.h"
- void createNewList(List &L){
- first(L) = NULL;
- }
- void insertLast(List &L, address p){
- address x;
- if (first(L) == NULL){
- first(L) = p;
- } else {
- x = first(L);
- while (next(x) != NULL){
- x = next(x);
- }
- next(x) = p;
- }
- }
- void deleteFirst(List &L, address &p){
- if (first(L) == NULL){
- cout << "List masakan kosong" << endl;
- } else {
- if (next(first(L)) == NULL){
- p = first(L);
- first(L) = NULL;
- } else {
- p = first(L);
- first(L) = next(p);
- }
- }
- }
- void deleteLast(List &L, address &p){
- if (first(L) == NULL){
- cout << "List masakan kosong" << endl;
- } else {
- if (next(first(L)) == NULL){
- p = first(L);
- first(L) = NULL;
- } else {
- address q;
- p = first(L);
- while (next(p) != NULL){
- q = p;
- p = next(p);
- }
- next(q) = NULL;
- }
- }
- }
- void deleteAfter(List &L, address prec, address &p){
- p = next(prec);
- if (next(p) == NULL){
- next(prec) = NULL;
- } else {
- next(prec) = next(p);
- next(p) = NULL;
- }
- }
- bool isEmpty(List L){
- address check = first(L);
- if(check != NULL){
- return false;
- }
- return true;
- }
- infotype newMasakan(int no,string nama){
- infotype data;
- data.nomor = no;
- data.nama = nama;
- data.sisaPorsi = S;
- return data;
- }
- address newElementList(infotype X){
- address P = new ElmtMsk;
- info(P) = X;
- next(P) = NULL;
- return P;
- }
- void addNelementList(List &L,int N){
- for(int x = 0;x<N;x++){
- int id;
- string nama;
- cout <<"Masukan ID makanan ke-"<<x+1<<" : ";
- cin >> id;
- cout <<"Masukan nama makanan ke-"<<x+1<<" : ";
- cin >> nama;
- infotype makanan = newMasakan(id,nama);
- insertLast(L,newElementList(makanan));
- }
- cout<<"Data berhasil ditambahkan"<<endl;
- }
- void showAllFood(List L){
- address p = first(L);
- if(p == NULL){
- cout << "Daftar makanan kosong" << endl;
- }
- cout << "Daftar Makanan : " << endl;
- while(p!= NULL){
- cout << info(p).nomor << "|" << info(p).nama << "|" << info(p).sisaPorsi << endl;
- p = next(p);
- }
- cout<<endl;
- }
- void showAvailableFood(List L){
- address p = first(L);
- if(p == NULL){
- cout << "Daftar makanan kosong" << endl;
- }
- cout << "Daftar Makanan yang tersedia : " << endl;
- while(p!= NULL){
- if(info(p).sisaPorsi < 0){
- continue;
- }
- cout << info(p).nomor << "|" << info(p).nama << "|" << info(p).sisaPorsi << endl;
- p = next(p);
- }
- cout<<endl;
- }
- address findMinRemaining(List L){
- address p = first(L);
- address currentVal = p;
- int minData = info(p).sisaPorsi;
- while(p!= NULL){
- if(info(p).sisaPorsi < minData){
- currentVal = p;
- minData = info(currentVal).sisaPorsi;
- }
- p = next(p);
- }
- return currentVal;
- }
- void showBestSeller(List L){
- address p = first(L);
- if(p != NULL){
- address currentBestSeller = findMinRemaining(L);
- cout<<"Makanan Best Seller saat ini : " << info(currentBestSeller).nama << endl;
- }else{
- cout<<"Data Makanan kosong" << endl;
- }
- }
- void deleteAllSoldOut(List &L){
- address p = first(L);
- if(p == NULL){
- return;
- }
- address last;
- while(p!= NULL){
- if(info(p).sisaPorsi == 0){
- if(last != NULL){
- address nextP = next(p);
- next(last) = nextP;
- p = nextP;
- }else{
- address nextP = next(p);
- first(L) = nextP;
- p = nextP;
- }
- }else{
- last = p;
- p = next(p);
- }
- }
- }
- void transaction(List &L,int no,int porsi){
- address p = first(L);
- if(p == NULL){
- return;
- }
- while(p!= NULL){
- if(info(p).nomor == no){
- info(p).sisaPorsi -= porsi;
- if(info(p).sisaPorsi < 0){
- info(p).sisaPorsi = 0;
- }
- return;
- }
- p = next(p);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement