Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,396 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,104 people online right now. Registration is fast and FREE... Join Now!




How to copy a Linked List

 
Reply to this topicStart new topic

How to copy a Linked List

sknox1
22 Oct, 2006 - 05:38 PM
Post #1

New D.I.C Head
Group Icon

Joined: 30 Sep, 2006
Posts: 29


Dream Kudos: 150
My Contributions
CODE


#include<iostream>
#include<list>
#include "d_util.h"

using namespace std;











template <typename T>
void splice(list<T>& dest, list<T>::iterator pos,
                const list<T>& source)
{
    list<T>::const_iterator sourceIter;

    sourceIter = source.begin();


int a[] = {5, 8, 4, 1, 7};
int b[] = {12, 3, 15, 6, 23, 1, 2};
int sizeA= sizeof(a)/sizeof(int), sizeB= sizeof(B)/sizeof(int);

list<int>list1(a, a+sizeA);
list<int>list2(b, b+sizeB);



How do i copy list2 to the back of list1

edit: fixed [code] tags, modified title ~ jayman9
User is offlineProfile CardPM
+Quote Post

gregoryH
RE: How To Copy A Linked List
23 Oct, 2006 - 12:22 AM
Post #2

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
QUOTE(sknox1 @ 22 Oct, 2006 - 06:38 PM) *

CODE


#include<iostream>
#include<list>
#include "d_util.h"

using namespace std;











template <typename T>
void splice(list<T>& dest, list<T>::iterator pos,
                const list<T>& source)
{
    list<T>::const_iterator sourceIter;

    sourceIter = source.begin();


int a[] = {5, 8, 4, 1, 7};
int b[] = {12, 3, 15, 6, 23, 1, 2};
int sizeA= sizeof(a)/sizeof(int), sizeB= sizeof(B)/sizeof(int);

list<int>list1(a, a+sizeA);
list<int>list2(b, b+sizeB);



How do i copy list2 to the back of list1

edit: fixed [code] tags, modified title ~ jayman9

hi sk

Are you wishing to implement that using STL functionality (ie push() etc ) or roll your own?
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:54AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month