Advertisement
ChaeYuriya

Assignment 9 : DLL.cpp

Nov 23rd, 2024
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include <iostream>
  2. #include "DLL.h"
  3.  
  4. using namespace std;
  5.  
  6. void CreateList(List &L){
  7.     first(L) = NULL;
  8.     last(L) = NULL;
  9. }
  10.  
  11. void InsertFirst(List &L,address P){
  12.     if(first(L) == NULL){
  13.         first(L) = P;
  14.         last(L) = P;
  15.         return;
  16.     }
  17.  
  18.     next(P) = first(L);
  19.     prev(first(L)) = P;
  20.     first(L) = P;
  21. }
  22.  
  23. void DeleteFirst(List &L, address &P){
  24.     P = first(L);
  25.     first(L) = next(P);
  26.  
  27.     if(first(L) != NULL){
  28.         prev(first(L)) = NULL;
  29.     }
  30.  
  31.     if(last(L) == P){
  32.         last(L) = NULL;
  33.     }
  34.  
  35.     next(P) = NULL;
  36.     prev(P) = NULL;
  37. }
  38.  
  39. address createNewElement(string name,float rating){
  40.     address P = new elmList;
  41.     next(P) = NULL;
  42.     prev(P) = NULL;
  43.     info(P).name = name;
  44.     info(P).rating = rating;
  45.  
  46.     return P;
  47. }
  48.  
  49. void ShowList(List &L){
  50.     address P = first(L);
  51.  
  52.     while(P != NULL){
  53.         cout<<"=================="<<endl;
  54.         cout<<"Data Driver" <<endl;
  55.         cout<<"Nama : " << info(P).name << endl;
  56.         cout<<"Rating : " << info(P).rating << endl;
  57.         cout<<"=================="<<endl;
  58.         P = next(P);
  59.     }
  60. }
  61.  
  62. void Reset(List &L){
  63.     float totalDriver;
  64.     float CurrentRate;
  65.     while(first(L) != NULL){
  66.         address P;
  67.         DeleteFirst(L,P);
  68.         cout<<"=================="<<endl;
  69.         cout<<"Delete Data Driver" <<endl;
  70.         cout<<"Nama : " << info(P).name << endl;
  71.         cout<<"Rating : " << info(P).rating << endl;
  72.         cout<<"=================="<<endl;
  73.         totalDriver++;
  74.         CurrentRate += info(P).rating;
  75.     }
  76.     CurrentRate = CurrentRate/totalDriver;
  77.     cout<<"Data List telah di reset"<<endl;
  78.     cout<<"Average rating : " << CurrentRate << endl;
  79. }
  80.  
  81. void SplitData(float N,List &L,List &under,List &upper){
  82.     while(first(L) != NULL){
  83.         address P;
  84.         DeleteFirst(L,P);
  85.         if(info(P).rating >= N){
  86.             InsertFirst(upper,P);
  87.         }else{
  88.             InsertFirst(under,P);
  89.         }
  90.     }
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement