public void push(nod value) //adaugare { n++; nod[] t = new nod[n]; for (int i = 0; i < n - 1; i++) //se decaleaza elementele cu o poz pt a elibera prima poz { t[i + 1] = v[i]; //mutam elementele pe o pozitie +1 la dreapta } t[0] = value; //se introduce valoarea pe prima pozitie v = t; }
public nod pop() //stergere { nod tor = v[n - 1]; //eliminam ultimul element n--; nod[] t = new nod[n]; for (int i = 0; i < n; i++) //copiem v-u in t, mai putin ultima val dat n-- de mai sus { t[i] = v[i]; } v = t; return(tor); //returnam elementul sters (pentru a stii pe care l-am sters) }
static void Lee() { Queue A = new Queue(); a[0, 0] = 1; A.push(new nod(0, 0, 1)); while (A.n != 0) { nod t = A.pop(); if (t.l - 1 >= 0) { if (a[t.l - 1, t.c] == 0) { a[t.l - 1, t.c] = t.v + 1; A.push(new nod(t.l - 1, t.c, t.v + 1)); } } if (t.c + 1 < m) { if (a[t.l, t.c + 1] == 0) { a[t.l, t.c + 1] = t.v + 1; A.push(new nod(t.l, t.c + 1, t.v + 1)); } } if (t.l + 1 < n) { if (a[t.l + 1, t.c] == 0) { a[t.l + 1, t.c] = t.v + 1; A.push(new nod(t.l + 1, t.c, t.v + 1)); } } if (t.c - 1 >= 0) { if (a[t.l, t.c - 1] == 0) { a[t.l, t.c - 1] = t.v + 1; A.push(new nod(t.l, t.c - 1, t.v + 1)); } } } }