Skip to main content
Log in

Mojo struct

Node

struct Node[ElementType: WritableCollectionElement]

A node in a linked list data structure.

Parameters

  • ElementType (WritableCollectionElement): 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, Writable

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__(self) -> String

Convert this node's value to a string representation.

Returns:

String representation of the node's value.

write_to

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

Write this node's value to the given writer.

Parameters:

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

Args:

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