Method in collections::list · List coil-stdlib

List::push_back

pub fn push_back(T v)
Import
use collections::list::{List};
Source: src/collections/list.hy

Adds v at the back. Walks the list, so it takes time proportional to its length.

Called on a List value as value.push_back(…).

Parameters#

NameType
vT

Contracts#

Checked according to --contracts (see Contracts).

ensures self.len == old(self.len) + 1

Examples#

use collections::list::{List};
use tests::assert;
let xs: List<int> = List::new();
xs.push_back(1);
xs.push_back(2);
let v = xs.to_vec();
assert!(v[1] == 2);

See also#

  • List: A singly-linked list with constant-time push and pop at the front.
  • List::new: Creates an empty list.
  • List::size: Returns the number of values.
  • List::is_empty: Returns true when the list has no values.
  • List::push_front: Adds v at the front.
  • List::peek_front: Returns the front value without removing it, or None when the list is empty.
  • List::pop_front: Removes and returns the front value, or None when the list is empty.
  • List::pop_back: Removes and returns the back value, or None when the list is empty.
↑ ↓ navigate ↵ open