Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "DLL.h"
- void createNewList(List &L){
- first(L) = NULL;
- last(L) = NULL;
- }
- address createElemen(infotype dataBaru){
- address P = new ElmtMsk;
- info(P) = dataBaru;
- next(P) = NULL;
- return P;
- }
- void insertLast(List &L, address p){
- address x;
- if (first(L) == NULL){
- first(L) = p;
- last(L) = p;
- } else {
- next(last(L)) = p;
- prev(p) = last(L);
- last(L) = p;
- }
- }
- void insertAfter(List &L, address &Prec,address &P){
- next(P) = next(Prec);
- prev(next(Prec)) = P;
- next(Prec) = P;
- prev(P) = Prec;
- }
- void deleteFirst(List &L, address &p){
- p = first(L);
- if(next(first(L)) == NULL){
- first(L) = NULL;
- last(L) = NULL;
- }else{
- first(L) = next(first(L));
- prev(first(L)) = NULL;
- next(p) = 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;
- }
- }
- void deleteLast(List &L, address &p){
- p = last(L);
- if(prev(p) != NULL){
- address lastest = prev(p);
- last(L) = lastest;
- next(lastest) = NULL;
- }else{
- last(L) = NULL;
- first(L) = NULL;
- }
- prev(p) = NULL;
- }
- void printList(List L){
- address p = first(L);
- while(p!=NULL){
- cout << info(p).title <<"||"<<info(p).url <<"||"<<info(p).timestamp <<"||"<<info(p).visitcount<< endl;
- p = next(p);
- }
- }
- void insertFirst(List &L,address P){
- if(first(L) == NULL){
- first(L) = P;
- last(L) = P;
- return;
- }
- prev(first(L)) = P;
- next(P) = first(L);
- first(L) = P;
- }
- void insertAscending(List &L,infotype dataBaru){
- address P = first(L);
- if(P == NULL){
- insertFirst(L,createElemen(dataBaru));
- }else{
- address datanew = createElemen(dataBaru);
- while(P != NULL){
- if(info(P).visitcount > info(datanew).visitcount){
- if(prev(P) == NULL){
- insertFirst(L,datanew);
- }else{
- address lastBefore = prev(P);
- insertAfter(L,lastBefore,datanew);
- }
- break;
- }else if(next(P) == NULL){
- insertLast(L,datanew);
- break;
- }
- P = next(P);
- }
- }
- }
- bool findElemen(List L,string X){
- address p = first(L);
- while(p!=NULL){
- if(info(p).title == X){
- return true;
- }
- p = next(p);
- }
- return false;
- }
- int moreThanOnce(List L){
- int total = 0;
- address p = first(L);
- while(p!=NULL){
- if(info(p).visitcount > 0){
- total++;
- }
- p = next(p);
- }
- return total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement