Skip to main content

Mojo struct

Node

struct Node[ElementType: ExplicitlyCopyable & Movable]

A node in a linked list data structure.

Parameters

Fields

  • value (ElementType): The value stored in this node.
  • prev (UnsafePointer[Node[ElementType]]): The previous node in the list.
  • next (UnsafePointer[Node[ElementType]]): The next node in the list.

Implemented traits

AnyType, Copyable, ExplicitlyCopyable, Movable, UnknownDestructibility

Aliases

__copyinit__is_trivial

alias __copyinit__is_trivial = False

__del__is_trivial

alias __del__is_trivial = get_witness(ElementType, stdlib::builtin::anytype::AnyType, __del__is_trivial)

__moveinit__is_trivial

alias __moveinit__is_trivial = get_witness(ElementType, stdlib::builtin::value::Movable, __moveinit__is_trivial)

Methods

__init__

__init__(out self, var value: ElementType, prev: Optional[UnsafePointer[Node[ElementType]]], next: Optional[UnsafePointer[Node[ElementType]]])

Initialize a new Node with the given value and optional prev/next pointers.

Args:

  • value (ElementType): The value to store in this node.
  • prev (Optional): Optional pointer to the previous node.
  • next (Optional): Optional pointer to the next node.

__copyinit__

__copyinit__(out self, existing: Self)

Creates a copy of the given node.

Args:

  • existing (Self): The node to copy.

__str__

__str__[ElementType: ExplicitlyCopyable & Movable & Writable](self: Node[ElementType]) -> String

Convert this node's value to a string representation.

Parameters:

Returns:

String: String representation of the node's value.

write_to

write_to[ElementType: ExplicitlyCopyable & Movable & Writable, W: Writer](self: Node[ElementType], mut writer: W)

Write this node's value to the given writer.

Parameters:

Args:

  • writer (W): The writer to write the value to.

Was this page helpful?