Struktur Data Algoritma Double Linked List dengan PseudoCode

Double Linked List adalah suatu struktur dalam pengerjaan coding yang di gunakan dalam Mata Kuliah Struktur Data, kali ini akan di bahas dan di berikan Coding Single Linked List dalam bentuk PseudoCode :

BACA JUGA : Struktur Data Algoritma Single Linked List dengan PseudoCode

Struct ADT

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

Allocate

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

BACA JUGA : Algoritma Single Linked List dalam bahasa C++

Find Element

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

Insert First

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

Insert Last

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

Insert After

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
			ext(P) ← next(prec) 
			prev(P) ← prec 
			prev(next(prec)) ← P 
			next(prec) ← P

BACA JUGA : Algoritma Single Linked List dalam bahasa C++

Delete First

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

Delete Last

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

Delete After

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
Loading...

Jika ada yang salah atau kurang paham mohon di berikan di kolom komentar 🙂

Related Post