Anonymous user
Singly-linked list/Element insertion: Difference between revisions
no edit summary
(→{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details) |
No edit summary |
||
Line 1,422:
set A [List new "A" [List new "B"]]
$A insertAfter [List new "C"]</lang>
=={{header|X86 Assembly}}==
Singly-linked list definition page contains contents of
Linked_List_Definition.asm. Heap_Alloc.asm is my own
implementation of a heap memory management system. It is
basic, small and not extensively tested, but it's worked
for me 100% of the time so far. At the time of this posting
the code for Heap_Alloc.asm was not posted anywhere on rosetta
code. I will post somewhere in the near future, probably in
the memory allocation task.
<lang x86asm>
; x86_64 Linux NASM
; Linked_List_Insert.asm
%ifndef INSERT
%define INSERT
%include "Linked_List_Definition.asm"
%include "Heap_Alloc.asm"
section .text
; rdi - link to insert after
; rsi - value that the new link will hold
Insert_After:
push rdi
push rsi
mov rdi, linkSize
call alloc
cmp rax, 0
je Memory_Allocation_Failure_Exception
pop rdi
mov dword [rax + value], edi
pop rdi
mov rsi, qword [rdi + next]
mov qword [rax + next], rsi
mov qword [rdi + next], rax
ret
%endif
</lang>
=={{header|zkl}}==
|