Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "DLL.h"
- #define first(L) L.first
- #define next(P) P->next
- #define prev(P) P->prev
- #define info(P) P->info
- #define judul(P) P->judul
- using namespace std;
- bool isEmpty(List L){
- if(first(L) == NULL)
- return false;
- return true;
- }
- void createList(List &L){
- first(L) = NULL;
- }
- void createNewElement(infotype X,address &P){
- info(P) = X;
- next(P) = NULL;
- prev(P) = NULL;
- }
- void createNewSong(infotype ID,string X,address &P){
- info(P) = ID;
- judul(P) = X;
- next(P) = NULL;
- prev(P) = NULL;
- }
- void insertFirst(List &L, address P){
- next(P) = first(L);
- prev(P) = NULL;
- first(L) = P;
- }
- void inserAfter(List &L, address &Target,address P){
- address cur = first(L);
- while(next(cur)!= NULL){
- if(cur == Target){
- address nextTarget = next(cur);
- next(cur) = P;
- prev(P)= cur;
- next(P) = nextTarget;
- if(nextTarget != NULL){
- prev(nextTarget) = P;
- }
- break;
- }
- cur = next(cur);
- }
- }
- void insertLast(List &L, address P){
- if(first(L) == NULL){
- insertFirst(L,P);
- }else{
- address cur = first(L);
- while(next(cur)!= NULL){
- cur = next(cur);
- }
- next(cur) = P;
- prev(P) = cur;
- }
- }
- void deleteFirst(List &L, address &P){
- P = first(L);
- address currentFirst = next(P);
- prev(currentFirst)= NULL;
- next(P) = NULL;
- prev(P) = NULL;
- first(L) = currentFirst;
- }
- void deleteAfter(List &L, address &Target,address &P){
- address cur = first(L);
- while(next(cur)!= NULL){
- if(cur == Target){
- P = next(cur);
- address nextVal = next(P);
- if(nextVal != NULL){
- prev(nextVal) = prev(P);
- next(cur) = next(P);
- }else{
- next(cur) = NULL;
- }
- next(P) = NULL;
- prev(P) = NULL;
- break;
- }
- cur = next(cur);
- }
- }
- void deleteLast(List &L, address &P){
- address cur = first(L);
- while(next(cur)!= NULL){
- cur = next(cur);
- }
- address beforeLast = prev(cur);
- next(beforeLast) = NULL;
- prev(cur) = NULL;
- }
- void concat(List L1, List L2, List &L3) {
- createList(L3);
- address cur = first(L1);
- while (cur != NULL) {
- address newElem = new elmList;
- info(newElem) = info(cur);
- next(newElem) = NULL;
- prev(newElem) = NULL;
- insertLast(L3, newElem);
- cur = next(cur);
- }
- cur = first(L2);
- while (cur != NULL) {
- address newElem = new elmList;
- info(newElem) = info(cur);
- next(newElem) = NULL;
- prev(newElem) = NULL;
- insertLast(L3, newElem);
- cur = next(cur);
- }
- }
- address getSongAddress(string judul,List L){
- address cur = first(L);
- while (cur != NULL) {
- if(judul == judul(cur)){
- return cur;
- }
- cur = next(cur);
- }
- return NULL;
- }
- void removeLagu(string judul,List &L){
- address cur = getSongAddress(judul,L);
- if(cur != NULL){
- address prevVal = prev(cur);
- address nextVal = next(cur);
- next(cur) = NULL;
- prev(cur) = NULL;
- if(prevVal != NULL){
- next(prevVal) = nextVal;
- }
- if(nextVal != NULL){
- prev(nextVal) = prevVal;
- }
- }
- }
- void printInfo(List L){
- address p = first(L);
- while(p!= NULL){
- cout << "==> " << info(p) <<"=" <<judul(p) << "<== "<<prev(p)<< "<>" << next(p)<< endl;
- p = next(p);
- }
- cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement