c++ - Copy constructor for a stack using linked list -



c++ - Copy constructor for a stack using linked list -

template <class t> stack<t>::stack(const stack<t>& otherstack) { list<t> the=otherstack.list; listitem<t> *temp=the.gethead(); while(temp!=null) { push(temp->value); temp=temp->next; } }

i using linked list create stack , re-create constructor not working. please help.

the re-create constructor of list<t> defined as:

template <class t> list<t>::list(const list<t>& otherlist) { head=null; listitem<t> *temp=otherlist.head; while (temp!=null) { insertattail(temp->value); temp=temp->next; } }

if list , stack have usual semantics, constructor reverses order of items in constructed object. should either traverse list in reverse order or such re-create twice restore original order. possible list can copied assignment operator ,

this.list = otherstack.list

is enough. not seeing list code can't tell.

c++

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -