Skip to content

aurora-learning-communicating/datastructure-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

DataStructure in Rust

1. 介绍

这是用 Rust 写的常用数据结构和算法,包含

  • linkedlist
  • binary search tree
  • avl
  • graph
  • 迪杰斯特拉算法
  • ...

2. 链表

2.1 create

  1. List::new()
  2. List::with_capacity(n: usize)

2.2 push

  1. push_back(value: T)
  2. push_front(value: T)

2.3 pop

  1. pop_back()
  2. pop_front()

2.4 iterate

  1. iter()
  2. iter_mut()

2.5 在某个节点后插入

#[test]
fn test_move_cursor() {
    let mut list = List::new();
    for value in 1..=10 {
        let _ = list.push_back(value);
    }
    
    let mut cursor = list.cursor_mut(|value| *value == 3);
    
    cursor.move_next();
    
    cursor.push_next(0);
    
    for value in list.iter() {
        println!("value: {}", value);
    }
}

2.6 在某个节点删除

#[test]
fn test_pop_at() {
    let mut list = List::new();
    for value in 1..=10 {
        let _ = list.push_back(value);
    }

    let mut cursor = list.cursor_mut(|value| *value == 3);

    cursor.pop();

    for value in list.iter() {
        println!("value: {}", value);
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages