You are on page 1of 14

SINGLE LINKED LIST

Type infotype : integer //dapat diganti sesuai kasus


Type address : pointer to elmlist
Type elmlist<
info : infotype
next : address
>
Type list < first : address >
L : list

Function allocate (X : infotype) → address


Kamus
P : address
Algoritma
P ← new elmlist
next(P) ← NULL
info(P) ← X
→P

Function findElm (L : list, X : infotype) → address


Kamus
Algortima
P ← first(L)
while ((P ≠ NULL) and (info(P) ≠ X)) do
P ← next(P)
if (info(P) = X) then
→P
else
→ NULL

Follow Us On :
bit.ly/oabrosist
@brother.code
Procedure insertFirst (input/output L : list, input P : address)
Kamus
Algoritma
if (first(L) = NULL) then
first(L) ← P
else
next(P) ← first(L)
first(L) ← P

Procedure insertLast (input/output L : list, input P : address)


Kamus
Q : address
Algoritma
if (first(L) = NULL) then
insertFirst(L, P)
else
Q ← first(L)
while (next(Q) ≠ NULL) do
Q ← next(Q)
next(Q) ← P

Procedure insertAfter (input/output L : list, input prec : address, input P : address)


Kamus
Algoritma
if ((first(L) ≠ NULL) and (prec ≠ NULL)) then
next(P) ← next(prec)
next(prec) ← P

Follow Us On :
bit.ly/oabrosist
@brother.code
Procedure deleteFirst(input/output L : list, output P : address)
Kamus
Algoritma
if (first(L) ≠ NULL) then
P ← first(L)
first(L) ← next(P)
next(P) ← NULL

Procedure deleteLast(input/output L : list, ouput P : address)


Kamus
Q : address
Algoritma
if (first(L) ≠ NULL) then
Q ← first(L)
if (next(Q) = NULL) then
deleteFirst(L, P)
else
while (next(next(Q)) ≠ NULL) do
Q ← next(Q)
P ← next(Q)
next(Q) ← NULL
next(P) ← NULL

Procedure deleteAfter(input/output L : list, input prec : address, output P : address)


Kamus
Algoritma
if ((first(L) ≠ NULL) and (prec ≠ NULL)) then
P ← next(prec)
next(prec) ← next(P)
next(P) ← NULL

Follow Us On :
bit.ly/oabrosist
@brother.code
DOUBLE LINKED LIST

Type infotype : integer //dapat diganti sesuai kasus


Type address : pointer to elmlist
Type elmlist<
info : infotype
next : address
prev : address
>
Type list <
first : address
last : address
>
L : list

Function allocate (X : infotype) → address


Kamus
P : address
Algoritma
P ← new elmlist
next(P) ← NULL
prev(P) ← NULL
info(P) ← X
→P

Function findElm (L : list, X : infotype) → address


Kamus
Algortima
P ← first(L)
while ((P ≠ NULL) and (info(P) ≠ X)) do
P ← next(P)
if (info(P) = X) then
→P
else
→ NULL

Follow Us On :
bit.ly/oabrosist
@brother.code
Procedure insertFirst (input/output L : list, input P : address)
Kamus
Algoritma
if (first(L) = NULL) then
first(L) ← P
last(L) ← P
else
next(P) ← first(L)
prev(first(L)) ← P
first(L) ← P

Procedure insertLast (input/output L : list, input P : address)


Kamus
Algoritma
if (first(L) = NULL) then
first(L) ← P
last(L) ← P
else
prev(P) ← last(L)
next(last(L)) ← P
last(L) ← P

Procedure insertAfter (input/output L : list, input prec : address, input P : address)


Kamus
Algoritma
if ((first(L) ≠ NULL) and (prec ≠ NULL)) then
if (next(prec) = NULL) then
insertLast(L, P)
else
next(P) ← next(prec)
prev(P) ← prec
prev(next(prec)) ← P
next(prec) ← P

Follow Us On :
bit.ly/oabrosist
@brother.code
Procedure deleteFirst (input/ouput L : list, ouput P : address)
Kamus
Algoritma
If (first(L) ≠ NULL) then
P ← first(L)
if (P = last(L)) then
first(L) ← NULL
last(L) ← NULL
else
first(L) ← next(P)
next(P) ← NULL
prev(first(L)) ← NULL

Procedure deleteLast (input/ouput L : list, ouput P : address)


Kamus
Algoritma
If (first(L) ≠ NULL) then
P ← last(L)
if (P = last(L)) then
first(L) ← NULL
last(L) ← NULL
else
last(L) ← prev(P)
prev(P) ← NULL
next(last(L)) ← NULL

Procedure deleteAfter (input/output L : list, input prec : address, output P : address)


Kamus
Algoritma
if ((first(L) ≠ NULL) and (prec ≠ NULL)) then
if (prec ≠ Last(L)) then
if (next(prec) = last(L)) then
deleteLast(L, P)
else
P ← next(prec)
next(prec) ← next(P)
prev(next(P)) ← prec
next(P) ← NULL
prev(P) ← NULL

Follow Us On :
bit.ly/oabrosist
@brother.code
CIRCULAR SINGLE LINKED LIST

Type infotype : integer //dapat diganti sesuai kasus


Type address : pointer to elmlist
Type elmlist<
info : infotype
next : address
>
Type list < first : address >
L : list

Function allocate (X : infotype) → address


Kamus
P : address
Algoritma
P ← new elmlist
next(P) ← NULL
info(P) ← X
→P

Function findElm (L : list, X : infotype) → address


Kamus
Algortima
P ← first(L)
repeat
P ← next(P)
until ((next(P) = first(L)) or (info(P) = X))
if (info(P) = X) then
→P
else
→ NULL

Follow Us On :
bit.ly/oabrosist
@brother.code
Procedure insertFirst (input/output L : list, input P : address)
Kamus
Q : address
Algoritma
if (first(L) = NULL) then
first(L) ← P
next(P) ← P
else
Q ← first(L)
while (next(Q) ≠ first(L)) do
Q ← next(Q)
next(Q) ← P
next(P) ← first(L)
first(L) ← P

Procedure insertLast (input/output L : list, input P : address)


Kamus
Q : address
Algortima
if (first(L) = NULL) then
first(L) ← P
next(P) ← P
else
Q ← first(L)
while (next(Q) ≠ first(L)) do
Q ← next(Q)
next(Q) ← P
next(P) ← first(L)

Procedure insertAfter (input/output L : list, input prec : address, input P : address)


Kamus
Algoritma
if ((first(L) ≠ NULL) and (prec ≠ NULL)) then
if (next(prec) = first(L) then
insertLast(L, P)
else
next(P) ← next(prec)
next(prec) ← P

Follow Us On :
bit.ly/oabrosist
@brother.code
Procedure deleteFirst(input/output L : list, output P : address)
Kamus
Q : address
Algoritma
if (first(L) ≠ NULL) then
P ← first(L)
if (next(P) = first(L)) then
next(P) ← NULL
first(L) ← NULL
else
Q ← first(L)
while (next(Q) ≠ first(L)) do
Q ← next(Q)
first(L) ← next(P)
next(Q) ← next(P)
next(P) ← NULL

Procedure deleteLast (input/ouput L : list, ouput P : address)


Kamus
Q : address
Algoritma
if (first(L) ≠ NULL) then
P ← first(L)
if (next(P) = first(L)) then
next(P) ← NULL
first(L) ← NULL
else
Q ← first(L)
while (next(next(Q)) ≠ first(L)) do
Q ← next(Q)
P ← next(Q)
next(Q) ← next(P)
next(P) ← NULL

Follow Us On :
bit.ly/oabrosist
@brother.code
Procedure deleteAfter(input/output L : list, input prec : address, output P : address)
Kamus
Algoritma
if ((first(L) ≠ NULL) and (prec ≠ NULL)) then
if (next(prec) = first(L)) then
deleteFirst(L, P)
else
P ← next(prec)
next(prec) ← next(P)
next(P) ← NULL

Follow Us On :
bit.ly/oabrosist
@brother.code
CIRCULAR DOUBLE LINKED LIST

Type infotype : integer //dapat diganti sesuai kasus


Type address : pointer to elmlist
Type elmlist<
info : infotype
next : address
prev : address
>
Type list <
first : address
last : address
>
L : list

Function allocate (X : infotype) → address


Kamus
P : address
Algoritma
P ← new elmlist
next(P) ← NULL
prev(P) ← NULL
info(P) ← X
→P

Function findElm (L : list, X : infotype) → address


Kamus
Algortima
P ← first(L)
repeat
P ← next(P)
until ((next(P) = first(L)) or (info(P) = X))
if (info(P) = X) then
→P
else
→ NULL

Follow Us On :
bit.ly/oabrosist
@brother.code
Procedure insertFirst (input/output L : list, input P : address)
Kamus
Algoritma
if (first(L) = NULL) then
first(L) ← P
last(L) ← P
next(P) ← P
prev(P) ← P
else
next(last(L)) ←P
prev(P) ←last(L)
next(P) ← first(L)
prev(first(L)) ← P
first(L) ← P

Procedure insertLast (input/output L : list, input P : address)


Kamus
Algoritma
if (first(L) = NULL) then
first(L) ← P
last(L) ← P
next(P) ← P
prev(P) ← P
else
next(last(L)) ← P
prev(P) ← last(L)
next(P) ← first(L)
prev(first(L)) ← P
last(L) ← P

Procedure insertAfter (input/output L : list, input prec : address, input P : address)


Kamus
Algoritma
if ((first(L) ≠ NULL) and (prec ≠ NULL)) then
if (next(prec) = first(L)) then
insertLast(L, P)
else
next(P) ← next(prec)
prev(P) ← prec
prev(next(prec)) ← P
next(prec) ← P

Follow Us On :
bit.ly/oabrosist
@brother.code
Procedure deleteFirst (input/ouput L : list, ouput P : address)
Kamus
Algoritma
If (first(L) ≠ NULL) then
P ← first(L)
if (P = last(L)) then
next(P) ← NULL
prev(P) ← NULL
first(L) ← NULL
last(L) ← NULL
else
first(L) ← next(P)
next(last(L)) ← first(L)
prev(first(L)) ← last(L)
next(P) ← NULL
prev(P) ← NULL

Procedure deleteLast (input/ouput L : list, ouput P : address)


Kamus
Algoritma
If (first(L) ≠ NULL) then
P ← last(L)
if (P = last(L)) then
next(P) ← NULL
prev(P) ← NULL
first(L) ← NULL
last(L) ← NULL
else
last(L) ← prev(P)
next(last(L)) ← first(L)
prev(first(L)) ← last(L)
next(P) ← NULL
prev(P) ← NULL

Follow Us On :
bit.ly/oabrosist
@brother.code
Procedure deleteAfter (input/output L : list, input prec : address, output P : address)
Kamus
Algoritma
if ((first(L) ≠ NULL) and (prec ≠ NULL)) then
if (prec ≠ Last(L)) then
if (next(prec) = last(L)) then
deleteLast(L, P)
else
P ← next(prec)
next(prec) ← next(P)
prev(next(P)) ← prec
next(P) ← NULL
prev(P) ← NULL
else
deleteFirst(L, P)

Follow Us On :
bit.ly/oabrosist
@brother.code

You might also like