java - Cloning a LinkList without using any builtin functions. -


i went interview today , question got thrown @ me. can't come answer.

the gig slist2 = slist1.clone();

if change things in slist1 (e.g editing object) not affect similar object in slist2. attempt it, create new nodes whenever cloning object part failed. thinking object.clone() question state no built-in function allowed.

slist2.head = new node(); node newlist = slist2.head;  node head = slist1.head; slist.head.(all data) = head.(all data); while(head.hasnext()){     head = head.next();     node newguy = newnode();     newnode.(all data) = node.(all data)     newlist.next = newguy; } 

this follow through old list, manually copying data new node , tacking node on new list


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -