Struktur Data Algoritma Circular Linked List dengan PseudoCode

Circular 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 Cicular 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 
>
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

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

Find Element

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

Insert First

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)
		{end while}
	next(Q) ← P 
	next(P) ← first(L) 
	first(L) ← P 

Insert Last

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)
		{end while}
	next(Q) ← P
	next(P) ← first(L) 

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) = first(L) then 
			insertLast(L, P) 
		else
			next(P) ← next(prec)
			next(prec) ← P

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

Delete First

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) 
			{end while}
			first(L) ← next(P) 
			next(Q) ← next(P) 
			next(P) ← NULL

Delete Last

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)
			{end while}
			next(Q) ← next(P)
			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
		if (next(prec) = first(L)) then 
			deleteFirst(L, P) 
		else
			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