Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "SLL.h"
- #define first(L) L.first
- #define next(P) P->next
- #define info(P) P->info
- #define judul(P) P->judul
- using namespace std;
- void createList(List &L){
- first(L) = NULL;
- }
- address alokasi(string X){
- address P = new elmList;
- info(P) = X;
- next(P) = NULL;
- return P;
- }
- void insertFirst(List &L, address P){
- next(P) = first(L);
- first(L) = P;
- }
- 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;
- }
- }
- 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;
- next(P) = nextTarget;
- break;
- }
- cur = next(cur);
- }
- }
- void deleteFirst(List &L, address &P){
- P = first(L);
- address currentFirst = next(P);
- next(P) = NULL;
- first(L) = currentFirst;
- }
- void deleteLast(List &L, address &P){
- address cur = first(L);
- while(next(cur)!= NULL){
- address check = next(cur);
- if(next(check) == NULL){
- next(cur) = NULL;
- cur = check;
- break;
- }
- cur = next(cur);
- }
- P = cur;
- }
- 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){
- next(cur) = next(P);
- }else{
- next(cur) = NULL;
- }
- next(P) = NULL;
- break;
- }
- cur = next(cur);
- }
- }
- void Show(List L){
- address p = first(L);
- if(p == NULL){
- cout << "Daftar produk kosong" << endl;
- return;
- }
- while(p!= NULL){
- cout << info(p);
- p = next(p);
- if(p!=NULL){
- cout << ", ";
- }
- }
- cout<<endl;
- }
- address findInfo(List L,string name){
- address cur = first(L);
- while (cur != NULL) {
- if(name == info(cur)){
- return cur;
- }
- cur = next(cur);
- }
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement