Skip to main content
Log in

Mojo struct

Node

struct Node[ElementType: CollectionElement]

A node in a linked list data structure.

Parameters

  • ElementType (CollectionElement): The type of element stored in the node.

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

Methods

__init__

__init__(out self, owned 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[UnsafePointer[Node[ElementType]]]): Optional pointer to the previous node.
  • next (Optional[UnsafePointer[Node[ElementType]]]): Optional pointer to the next node.

__str__

__str__[ElementType: WritableCollectionElement](self: Node[ElementType]) -> String

Convert this node's value to a string representation.

Parameters:

  • ElementType (WritableCollectionElement): Used to conditionally enable this function if ElementType is Writable.

Returns:

String representation of the node's value.

write_to

write_to[ElementType: WritableCollectionElement, W: Writer](self: Node[ElementType], mut writer: W)

Write this node's value to the given writer.

Parameters:

  • ElementType (WritableCollectionElement): Used to conditionally enable this function if ElementType is Writable.
  • W (Writer): The type of writer to write the value to.

Args:

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