#include <stdio.h>

#include "complex.hpp"
#include "sparse.hpp"

void show(const char *name, const Complex& c)
{
    printf("%-6s %g%+gi\n", name, c.GetRe(), c.GetIm());
}

int main()
{
    Complex z(1, -2);
    SparseArray<Complex*> s(0);         /* default: no object */
    s[1] = &z;

    s[1]->Set(5, 6);
    show("z:", z);
    try {
        s[9]->Set(100, 100);            /* a missing element */
        printf("not reached\n");
    }
    catch (const NullElement& ex) {
        printf("element %d has no object\n", ex.Index());
    }
    if (s[9] != 0)                      /* or check before using -> */
        s[9]->Set(100, 100);
    printf("stored: %d\n", s.NonzeroCount());
    return 0;
}
