# LightGraphs basic usage

**URL:** <https://discourse.julialang.org/t/lightgraphs-basic-usage/37088>\
**Category:** Specific Domains\
**Created:** [April 6, 2020, 4:50am UTC](https://discourse.julialang.org/t/lightgraphs-basic-usage/37088 "2020-04-06T04:50:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adriel](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Adriel](https://discourse.julialang.org/u/Adriel)\
**Post date:** [April 6, 2020, 4:50am UTC](https://discourse.julialang.org/t/lightgraphs-basic-usage/37088/1 "2020-04-06T04:50:40Z")

</div>

Noob question. How do I add a vertex to a graph and get its value, as in the following code fragment?

```julia
add_vertex!(g)
v = maximum(vertices(g)) # better way to do this?
add_edge!(g, cur, v)
cur = v

```

That works for simple cases where no vertices have been removed, but probably isn’t very efficient. Is there a canonical way to do it?

---

<div class="post-metadata">

**Author:** ![anon94023334](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@anon94023334](https://discourse.julialang.org/u/anon94023334)\
**Post date:** [April 6, 2020, 10:34pm UTC](https://discourse.julialang.org/t/lightgraphs-basic-usage/37088/2 "2020-04-06T22:34:08Z")

</div>

just use `nv(g)`:

```julia
add_vertex!(g)
v = nv(g)
add_edge!(g, cur, v)
cur = v

```

The “more correct” way to do this is to understand that `add_vertex!` adds to to the end of the range that describes vertices, and use `last(vertices(g))` instead of `nv`, but they’re essentially the same in terms of complexity.
