## Nidaa87

I need help on how to integrate elements linked to the rank list.i already have a list of seven figures to be that the elements that must be included in the right of such a position that the salary arrangement upward
And the work of the Union and the intersection between 2 nodes

## Nidaa87

Please help as soon as possible because with me just one day to hand over the post

## Ancient Dragon 5,243

It might help to explain your problem is you show something that illustrates what you want to do, because I have no clue what you want.

## Nidaa87

I want the code process
Union
And the intersection between the two linked list

## Salem 5,138

So what you really want to start with is something simple like "isMemberOf".

A union is merely a membership test to see if the item is in either list.
An intersection is a membership test to see if the item is in both lists.

How much of the list functionality do you have already, say
- create a list
- insert into a list
- remove from a list.
These are all basic functions which you'll need. If you can't do that much, then we need to help you with those rather than going straight for the complete solution.

## Nidaa87

And I have stayed code gymnasts European currencies and the intersection only House 2 linked list
List1, list2
For example:
List 1 = (1,3,5,7,8)
List2 = (1,9,1,3,5,2)
List1 union list2 = (1,3,5,7,8,9,2)
List1 intersection list2 =) 1,3,5)

## Nidaa87

``````#include <iostream>
#include <string>

using namespace std;

struct node
{
int data;
struct node *next;
};

{
public:
void create();
void display();
void selectionSort();
void unita();
void intre();
};

{
node *newl=NULL,*end=newl;
int data;
cout<<"\nCreate the List. Press <ENTER> after each entry\n";
for(int i=0;i<=5;i++)
{
cout<<"Enter a number: ";
cin>>data;
newl = new node;
newl->data=data;
else
end->next=newl;
end=newl;
end->next=NULL;

}
cout<<"\nList is Created\n";
}

{
node *start;
while(start!=NULL){
cout<<start->data;
if(start->next!=NULL)
cout<<", ";
start=start->next;
}
}
{
node *i, *j;
int temp;
for(j=i->next;j!=NULL;j=j->next){
if(i->data > j->data){
temp = i->data;
i->data = j->data;
j->data = temp;
}
}
}
cout<<"\nThe numbers are Sorted\n";
}
{
node *i, *j;
int data;
cout<<"Enter a number: ";
cin>>data;
j = new node;
j->data=data;
int temp;
if(i->data > j->data){
temp = i->data;
i->data = j->data;
j->data = temp;
}
}
}

void main()
{
list1.create();
cout<<"List1 before sorting "<<endl;
list1.display();
list1.selectionSort();
cout<<"List1 after sorting "<<endl;
list1.display();
list2.create();
cout<<"\n\n\n List2 before sorting "<<endl;
list2.display();
list2.selectionSort();
cout<<"List2 after sorting "<<endl;
list2.display();
list1.display();

}``````

## Lerner 582

Your formatting leaves a lot to be desired.

``````void linkedList :: create()
{
node *newl = NULL;
node *end = newl;
int data;

cout << "\nCreate the List. Press <ENTER> after each entry\n";
for(int i = 0; i <= 5; i++)
{
cout << "Enter a number: ";
cin >> data;
newl = new node;
newl->data = data;
else
end->next = newl;
end = newl;
end->next = NULL;
}
cout << "\nList is Created\n";
}``````

Note consistent indenting, spaces before and after operators, etc. It's not only easier to read code that's consistently and appropriately formatted, it's easier to debug too.

Assuming the posted code works as desired then the next step I would do is to decide exactly what constitutes a union. By that I mean do you have only one copy of a given value of data in the union or can you have multiple copies of data in the union? If you can have multiple copies, then just copy one list into the other to get the union. If you want unique copies of data in the union but there are multiple copies of data in either list then you need to get a little more creative.

Likewise, to me intersection means a list that has unique pieces of data that are in both lists from which the intersection is derived. Therefore pick one list as the target and one list as the source. Then you could use a nested loop something like for each node in the source check each node in the target. If a match is found look at each node the intersection. If matched node of the two lists isn't in the intersection then add it to the intersection.

## Nidaa87

I did not understand what it mean MY English is not good
I want the code works the intersection of Union and two list type integer

## Salem 5,138

Like I said, a function called "isMemberOf" would be a really useful primitive for working out intersection and union

``````// return true if val is in the list

{
??
??
??
??
??}

## Salem 5,138

In pseudo-code

Intersection
for e = each element in l1
if isElementOf(l2,e) then add e to the result

Union
copy l1 to the result
for e = each element in l2
if NOT isElementOf(result,e) then add e to the result

## Ancient Dragon 5,243

I think the job of that function is to create a third linked list that is the union of l1 and l2

``````Void uinio(linkedlist l1,linkedlist l2)
{
struct node* l3 = 0;
struct node* node = l1;
// add the unique node in l1 to the new linked list
while( node )
{
if( !IsMemberOf(l3, node->data) )
{
// add node->data to l3 list
}
node = node->next;
}
// do the same thing with l2
node = l2;
while( node )
{
if( !IsMemberOf(l3, node->data) )
{
// add node->data to l3 list
}
node = node->next;
}

}``````

## Nidaa87

I thank you very Abietin but this sentence error

## Nidaa87

If allowed to be what I Tcherhali work isElementOf

## Ancient Dragon 5,243

Post your current code so that we can see what you may have done wrong.

## Nidaa87

Why Ietunai error on this sentence bool linkedList:: isMemberOf (int val);

## Salem 5,138

Yes, we got that much of the problem already.

The question is, did you just put `bool isMemberOf (int val);` into the class declaration, without bothering to implement it, or have you tried to implement it and gotten some error messages.