473,232 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,232 software developers and data experts.

operator+ , Linked list

33
I have two linked list and I want to Concatenates these two linked lists, placing the elements of the second list after the elements of the first list. For example, if list1={1,2,3} and list2={4,5,6} then calling:

list3 = list1 + list2;
would result in list3={1,2,3,4,5,6}.

so I want to define operator+ for these linked list
any idea how I can do this?
Feb 13 '08 #1
8 4934
Ganon11
3,652 Expert 2GB
You would override

Expand|Select|Wrap|Line Numbers
  1. List& List::operator+(const List& rightHandSide);
with the appropriate code.

Now, how can you get the last element of the List to point to the first element of rightHandSide?
Feb 13 '08 #2
APEJMAN
33
You would override

Expand|Select|Wrap|Line Numbers
  1. List& List::operator+(const List& rightHandSide);
with the appropriate code.

Now, how can you get the last element of the List to point to the first element of rightHandSide?
I am confused
I dont know
Feb 13 '08 #3
APEJMAN
33
Lets say I have

//Operator + , concatenates two linked lists
template <typename T>
LinkedList<T>& LinkedList<T>::operator+ (const LinkedList<T>& right)
{

}

I am trying to write the + operator so that I can add two linked list together like
list3=list1+list2;

any idea?
Thanks
Feb 14 '08 #4
Laharl
849 Expert 512MB
Think about it in terms of moving the pointers in the list. Which pointer(s) would need to be moved?

EDIT: Please don't post two threads on the same topic.
Feb 14 '08 #5
APEJMAN
33
we dont need to move any thing
just to make this work
link3=link1+link2

the declaration for the link list is:
Node<T>* newNode=new Node<T>(value)

any idea?
thanks
Feb 14 '08 #6
Ganon11
3,652 Expert 2GB
How are you confused? With which part? To help you, we need a little more description than "I don't know."
Feb 14 '08 #7
Ganon11
3,652 Expert 2GB
As Laharl said, please don't make two threads on the same topic. It doesn't help you get your help faster, it only makes things very confusing for the people trying to help you - thus causing them not to want to help. In short, you only need one thread for your topic.
Feb 14 '08 #8
APEJMAN
33
I fixed it
here is the code
this can add 2 linked list to gether

template <typename T>
LinkedList<T> LinkedList<T>::operator+ (const LinkedList<T>& right)
{
LinkedList result(*this);
for (int i=0 ; i<right.size() ; i++)
result.push_back(right[i]);
return result;
}
Feb 14 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ganesh.tambat | last post by:
Hi, Please see below a piece of code. Here I am trying to create a linked list by attaching two linked list together. I have overloaded operator + for this. Now the output always says that the...
5
by: Dream Catcher | last post by:
1. I don't know once the node is located, how to return that node. Should I return pointer to that node or should I return the struct of that node. 2. Also how to do the fn call in main for that...
6
by: Steve Lambert | last post by:
Hi, I've knocked up a number of small routines to create and manipulate a linked list of any structure. If anyone could take a look at this code and give me their opinion and details of any...
17
by: Ashwin | last post by:
hi guys, i have overloaded the << operator.as shown below. ostream& operator<<(ostream &out, const student &a) { out<<a.idno; out<< " " ; // out<< a.name; out<< " " ; // out<< a.marks...
16
by: EM.Bateman | last post by:
Working on Visual Studio .Net I've implemented a class: #ifndef CONTRIBUTOR_H #define CONTRIBUTOR_H enum Gender {male=1, female, unk}; #include <iostream> #include <iomanip> #include...
13
by: JD | last post by:
Hi, My associate has written a copy constructor for a class. Now I need to add an operator = to the class. Is there a way to do it without change her code (copy constructor) at all? Your help...
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
8
by: Rahul | last post by:
Please read the following code class Test{ public: void * operator new (size_t t) { return malloc(t); } void operator delete (void *p) { free(p); } };
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.