# ListTrace

> ListTrace holds the steps of a linked list, a stack or a queue.

Page: https://fframes-kit.pages.dev/docs/computer-science/list-trace/
Cargo feature: `cs` (`fframes-kit = { version = "..", features = ["cs"] }`)

`ListTrace` holds the steps of a linked list, a stack or a queue. Each `ListStep` has the
items in order, each with an id that stays with it from step to step (so the figures can
move, add and remove items smoothly), the links when they are not simply each item to the
next, the highlighted items, a found item, named pointers and a note.
`ListTrace::record(&values)` starts a `ListRecorder`; every operation adds the steps that
show it, and `finish` gives the trace:

- stack: `push`, `pop` (the item lights up, then leaves), `peek`;
- queue: `enqueue`, `dequeue`, `peek_front`;
- linked list: `insert(index, value)` and `remove(index)` walk a `cur` pointer to the node
  before, `find(value)` walks until it finds the value, and `reverse` walks `prev`, `cur`
  and `next` along while each link turns back, then puts the nodes in their new order;
- `note` replaces the note of the last step.

Gallery scene: `ListTrace` shows an insert, a removal and a reversal.

Gallery clip of `ListTrace`: https://fframes-kit.pages.dev/media/scenes/ListTrace-dccf1c30.mp4

```rust
use fframes_kit::prelude::*;

let list = ListTrace::record(&[3, 8, 1]).insert(2, 5).remove(0).reverse().finish();
assert_eq!(list.result(), ["1", "5", "8"]);

let stack = ListTrace::record(&[4]).push(7).pop().finish();
assert_eq!(stack.result(), ["4"]);

fn draw<'a>(ui: &mut Ui<'a, '_, '_>, trace: &'a ListTrace) -> Svgr<'a> {
    ui.show(LinkedList { trace: Some(trace), step_time: 0.7, ..ui.defaults() })
}
```
