3375


Algosy ćwiczenia nr 3

Temat: Listy rekurencyjne.

class ListaR

{

int wart; //głowa

ListaR ogon;

ListaR (int x) {...}

ListaR (int x, ListaR ogon) {...}

class x

{ ListaR l=null;

...

int m=l.maxWart();

}

int maxWart()

{

if (ogon==null) return wart;

else return Math.max(wart, ogon.maxWart());

}

static ListaR naKoniec (int x; ListaR l)

{

if (l==null) l=new ListaR(x);

else

l.ogon=ogon.naKoniec(x, l.ogon);

return l;

}

static ListaR wstawZa (int x, ListaR za, ListaR l)

{

if (za==null) l=new ListaR(x,l);

else za.ogon=new ListaR(x, za.ogon);

return l;

}

ListaR usun(int x)

{

if (wart==x) return ogon;

else{

if (ogon!=null) ogon=ogon.usun(x);

return this;

}

}

----koniec----



Wyszukiwarka

Podobne podstrony:
3375
3375
3375
3375
3375
3375

więcej podobnych podstron