```
#include "node.h"
#include <cassert> //assert
Node::Node (int nodeVal, Node *nextPtr) : value (nodeVal), next (nextPtr)
{
// std::cout << "Konstruktor Node" << std::endl;
}
Node *Node::insert (int newValue) {
next = new Node (newValue, next);
assert (next != 0); //koll fr att next != 0
return next;
}
```

```
#ifndef NODE_H
#define NODE_H
#include <iostream>
class Node
{
public:
Node(int, Node*); //constructor
Node *insert(int value); //member function
private:
int value;
Node *next;
friend class Set;
friend std::ostream& operator << (std::ostream &os, const Set &theSet);
};
#endif
```

```
#include "set.h"
#include <istream>
using namespace std;
Set::Set() {
header = new Node(0,0);
// cout << "Empty constructor " << endl;
}
Set::Set(int a[], int n) {
header = new Node(0,0); //skapar ny lista
Node *temp = header; //temp tilldelas start vrdet fr listan
int i = 0;
while(i < n+1) {
temp->next = new Node(a[i],0); //nsta uttrymme p listan tilldelas vrde frn a[i]
temp = temp->next; //
i++;
}
// cout << "Created constructor" << endl;
}
Set::Set(const Set& b) {
header = new Node(0,header);
Node *temp = header;
Node *templist = b.header -> next;
while (templist != 0)
{
temp -> next = new Node (templist->value, 0);
temp = temp -> next;
templist = templist -> next;
}
}
Set::~Set() {
delete header;
}
bool Set::empty () const {
Node *temp = header;
temp = temp->next;
if(temp == 0) {
return true;
}
return false;
}
int Set::cardinality() const {
Node *temp = header;
temp = temp->next;
int count = 0;
while(temp->next != 0) {
temp = temp->next;
count++;
}
return count;
}
bool Set::member (int x) const {
Node *temp = header;
temp = temp->next;
while(temp->next != 0) {
if(temp->value == x) {
return true;
}
temp = temp->next;
}
return false;
}
Set Set::operator+ (const Set& b) {
Node *tmp = header;
Set out = b;
tmp = tmp->next;
int i = 0;
while (tmp->next != 0 && i != 9) {
out.insert(tmp->value);
tmp = tmp->next;
i++;
}
return out;
}
void Set::insert (int value) {
// Node *temp = header;
// while(temp->next != 0) {
// cout << "Occupied by: "<< temp->value << endl;
// temp = temp->next;
//
// }
// temp->next = new Node(value,temp->next);
Node *temp = header;
bool exist = false;
while (temp->next != 0) {
if(temp->value == value && !exist) {
cout << "Exist " << endl;
exist = true;
break;
}
temp = temp->next;
}
if(!exist)
header->next = new Node(value, header->next);
}
std::ostream& operator << (std::ostream& out, const Set& b) {
Node *temp = b.header;
temp = temp -> next;
if (temp == 0) {
out << "Empty";
} else {
while(temp->next != 0) {
out << temp->value << " ";
temp = temp->next;
}
}
return out;
}
```

```
/*
Name: set.h
Author: Kenneth Bjerner
Date: 04-02-04 11:31
Description: Definitionsfil fr klassen Set
*/
#ifndef SET_H
#define SET_H
#include "node.h"
#include <iostream>
class Set {
public:
Set ();
Set (int a[], int n);
Set (const Set& b);
~Set ();
bool empty () const;
int cardinality() const;
bool member (int x) const;
Set operator+ (const Set& b);
// Set operator* (const Set& b);
// Set operator- (const Set& b);
// Set operator+(int x) const;
// Set operator-(int x) const;
// bool operator<=(const Set& b) const;
// bool operator==(const Set& b) const;
// bool operator<(const Set& b) const;
// Set& operator=(const Set& b);
//
private:
Node *header;
friend std::ostream& operator << (std::ostream& os, const Set& b);
void insert (int value);
void del (int value);
};
#endif
```