Struktur Data Algoritma Single Linked List dengan PseudoCode

Single 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 Double Linked List dengan PseudoCode

Struct ADT

Type infotype  : integer //dapat diganti sesuai kasus
Type address   : pointer to elmlist
Type elmlist < 
	info : infotype 
	next : address 
>
Type list  < 
	first : address 
> 
L : list

Allocate

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

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
	else
		next(P) ← first(L)
		first(L)  ← P

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

Insert Last

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

Insert After

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

Delete First

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

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

Delete Last

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 

Delete After

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

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

Related Post