You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
miguel 7ae7edf5fc renaming the tuples exercise 2 years ago
..
README.md renaming the tuples exercise 2 years ago

README.md

generics_list

Instructions

Create a linked list of generic values with the following methods.

  • new which returns a new empty list.

  • push which adds at the beginning of the list a new element.

  • pop which deletes the last added element to the list.

  • len which returns the size of the list.

Expected Functions

#[derive(Clone, Debug)]
pub struct List<T> {
    pub head: Option<Node<T>>,
}

#[derive(Clone, Debug)]
pub struct Node<T> {
    pub value: T,
    pub next: Option<Box<Node<T>>>,
}

impl<T> List<T> {
    pub fn new() -> List<T> {
    }

    pub fn push(&mut self, value: T) {
    }

    pub fn pop(&mut self) {
    }

    pub fn len(&self) -> usize {
    }
}

Usage

Here is a program to test your function.

use generics_list::*;

fn main() {
    let mut new_list_str = List::new();
    new_list_str.push("String Test 1");
    println!("The size of the list is {}", new_list_str.len());

    new_list_str.push("String Test 2");
    println!("The size of the list is {}", new_list_str.len());

    new_list_str.push("String Test 3");
    println!("The size of the list is {}", new_list_str.len());

    new_list_str.pop();
    println!("The size of the list is {}", new_list_str.len());
}

And its output

$ cargo run
The size of the list is 1
The size of the list is 2
The size of the list is 3
The size of the list is 2
$