16
правок
Изменения
→Псевдокод: EmptyStackException
== Псевдокод ==
fun '''pop'''(): Int { while (true) { <font color=green>//Cas loop</font>
head = H
if (CAS (&H, head, head.next))
}
}
fun '''push'''(x: Int) { while (true) { <font color=green>//Cas loop</font>
head = H
if (head == null)
throw new EmptyStackException();
newHead = Node {value: x, next: head}
if (CAS (&H, head, newHead))