can someone help me with my operator+ function.. I tested it in main with the fo
ID: 674346 • Letter: C
Question
can someone help me with my operator+ function.. I tested it in main with the following code list3=operator+(*list1,*list2);and received a random huge number as an output and sometimes it just stops working.
sortedListNode* operator+(sortedListNode &listl;, sortedListNode &list2;) sortedListNode *new,List = NULL; sortedListNode *templ = &list1; sortedListNode *temp2 = &list2; while(temp! != NULL && temp2 ! NULL) sortedListNode *newNode new sortedListNode; if(templ->lettertemp2- letter) sortedListNode *newNode = new sortedListNode; newNode->letter temp1-letter newNode-occurrences templ- Soccurrences templ temp1-next; else if(templ->letter > temp2->letter) newNode->letter temp2->letter; newNode-occurrences temp2- Soccurrences temp2 = temp2->next; else sortedListNode *newNode = new sortedListNode; newNode->letter = temp!->letter;
Explanation / Answer
SortedListNode< T > Generic.SortedListNode< T >.copy
(
)
Reimplemented from Generic.ListNode< T >.
void Generic.SortedListNode< T >.init
(
)
Construct a new empty ListNode<T>.
Reimplemented from Generic.ListNode< T >.
void Generic.SortedListNode< T >.init
(
T
v,
SortedListNode< T >
t
)
Construct a new SortedListNode<T>.
Parameters:
v
the new node's value
t
the new node's tail
Reimplemented from Generic.ListNode< T >.
void Generic.SortedListNode< T >.insert
(
T
v,
int(T, T)
compare
)
Insert a value into this list at appropriate position.
Parameters:
v
value to insert
compare
sort order to apply
void Generic.SortedListNode< T >.insert
(
T
v
)
Attention:
not implemented
Reimplemented from Generic.ListNode< T >.
public class SortedListNode implements Comparable
{
public int node = -1;
public int reach = 0;
public int compareTo(Object obj)
{
SortedListNode n = (SortedListNode)obj;
if(n.reach > this.reach)
{
return 1;
}
else if(n.reach < this.reach)
{
return -1;
}
else
{
return 0;
}
}
}
SortedListNode< T > Generic.SortedListNode< T >.copy
(
)
Reimplemented from Generic.ListNode< T >.
void Generic.SortedListNode< T >.init
(
)
Construct a new empty ListNode<T>.
Reimplemented from Generic.ListNode< T >.
void Generic.SortedListNode< T >.init
(
T
v,
SortedListNode< T >
t
)
Construct a new SortedListNode<T>.
Parameters:
v
the new node's value
t
the new node's tail
Reimplemented from Generic.ListNode< T >.
void Generic.SortedListNode< T >.insert
(
T
v,
int(T, T)
compare
)
Insert a value into this list at appropriate position.
Parameters:
v
value to insert
compare
sort order to apply
void Generic.SortedListNode< T >.insert
(
T
v
)
Attention:
not implemented
Reimplemented from Generic.ListNode< T >.
public class SortedListNode implements Comparable
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.