I want to add an element to the list before the selected one. could anyone fix my code? Because it doesn't work for me.
Code:List *get(int n) { List *pcurr = h; for (int i = 0; i < n; i++) pcurr = pcurr->n; return pcurr; } void add(int n, int x) { List *pnew = new List; List *pcurr = get(n); pnew->x = x; if (h == NULL) { h = pnew; pnew->n = pnew; } else { pnew->n = pcurr; pcurr->n->n = pnew; if (n == 0) h = pnew; } }