//main.cpp
#include "header.h"
#include "linkedList.cpp"
int main()
{
cout << "*************************PROGRAM*********************************";
cout << "\nFind and Delete the node with the smallest info in the list and"
<< "\nFind and Delete all occurrences of a given info from the list .";
unorderedLinkedList<int> myList;
cout << "\n\nInserting random numbers into the list.";
myList.insertFirst(3);
myList.insertFirst(15);
myList.insertFirst(22);
myList.insertLast(1);
myList.insertFirst(31);
myList.insertFirst(48);
myList.insertFirst(57);
myList.insertFirst(87);
myList.insertFirst(67);
cout << "\n\n\tThe elements in the list : ";
myList.print();
cout << "\n\tDeleting all occurrences of the smallest element.";
myList.deleteAllSmall();
cout << "\n\n\tThe elements in the list : ";
myList.print();
cout << "\n\tDeleting first occurrence of the smallest element.";
myList.deleteSmallest();
cout << "\n\n\tThe elements in the list : ";
myList.print();
cout << "\n\n\t";
system("pause");
return 0;
}
//header.h
#include<iostream>
using std::cout;
using std::cin;
#ifndef H_NodeType
#define H_NodeType
template<class Type>
struct nodeType
{
Type info;
nodeType<Type> *link;
};
#endif
template <class Type>
class linkedListIterator
{
public:
linkedListIterator();
linkedListIterator(nodeType<Type> *ptr);
Type operator*();
linkedListIterator<Type> operator++();
booloperator==(const linkedListIterator<Type> &right) const;
booloperator!=(const linkedListIterator<Type> &right) const;
private:
nodeType<Type> *current;
};
template<class Type>
linkedListIterator<Type>::linkedListIterator()
{
current = NULL;
}
template<class Type>
linkedListIterator<Type>::linkedListIterator
(nodeType<Type> *ptr)
{
current = ptr;
}
template<class Type>
Type linkedListIterator<Type>::operator*()
{
return current->info;
}
template<class Type>
linkedListIterator<Type> linkedListIterator<Type>::operator++()
{
current = current->link;
return *this;
}
template<class Type>
bool linkedListIterator<Type>::operator==(const linkedListIterator<Type>& right) const
{
return (current == right.current);
}
template<class Type>
bool linkedListIterator<Type>::operator!=(const linkedListIterator<Type>& right) const
{
return (current != right.current);
}
exit status 1
In file included from linkedList.cpp:1,
from main.cpp:2:
header.h:16:7: error: redefinition of 'class linkedListIterator<Type>'
class linkedListIterator
^~~~~~~~~~~~~~~~~~
In file included from main.cpp:1:
header.h:16:7: note: previous definition of 'class linkedListIterator<Type>'
class linkedListIterator
^~~~~~~~~~~~~~~~~~
In file included from linkedList.cpp:1,
from main.cpp:2:
header.h:40:1: error: redefinition of 'linkedListIterator<Type>::linkedListIterator()'
linkedListIterator<Type>::linkedListIterator()
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from main.cpp:1:
header.h:40:1: note: 'linkedListIterator<Type>::linkedListIterator()' previously declared here
linkedListIterator<Type>::linkedListIterator()
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from linkedList.cpp:1,
from main.cpp:2:
header.h:45:1: error: redefinition of 'linkedListIterator<Type>::linkedListIterator(nodeType<Type>*)'
linkedListIterator<Type>::linkedListIterator
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from main.cpp:1:
header.h:45:1: note: 'linkedListIterator<Type>::linkedListIterator(nodeType<Type>*)' previously declared here
linkedListIterator<Type>::linkedListIterator
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from linkedList.cpp:1,
from main.cpp:2:
header.h:51:6: error: redefinition of 'Type linkedListIterator<Type>::operator*()'
Type linkedListIterator<Type>::operator*()
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from main.cpp:1:
header.h:51:6: note: 'Type linkedListIterator<Type>::operator*()' previously declared here
Type linkedListIterator<Type>::operator*()
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from linkedList.cpp:1,
from main.cpp:2:
header.h:57:26: error: redefinition of 'linkedListIterator<Type> linkedListIterator<Type>::operator++()'
linkedListIterator<Type> linkedListIterator<Type>::operator++()
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from main.cpp:1:
header.h:57:26: note: 'linkedListIterator<Type> linkedListIterator<Type>::operator++()' previously declared here
linkedListIterator<Type> linkedListIterator<Type>::operator++()
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from linkedList.cpp:1,
from main.cpp:2:
header.h:63:6: error: redefinition of 'bool linkedListIterator<Type>::operator==(const linkedListIterator<Type>&) const'
bool linkedListIterator<Type>::operator==(const linkedListIterator<Type>& right) const
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from main.cpp:1:
header.h:63:6: note: 'bool linkedListIterator<Type>::operator==(const linkedListIterator<Type>&) const' previously declared here
bool linkedListIterator<Type>::operator==(const linkedListIterator<Type>& right) const
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from linkedList.cpp:1,
from main.cpp:2:
header.h:68:6: error: redefinition of 'bool linkedListIterator<Type>::operator!=(const linkedListIterator<Type>&) const'
bool linkedListIterator<Type>::operator!=(const linkedListIterator<Type>& right) const
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from main.cpp:1:
header.h:68:6: note: 'bool linkedListIterator<Type>::operator!=(const linkedListIterator<Type>&) const' previously declared here
bool linkedListIterator<Type>::operator!=(const linkedListIterator<Type>& right) const
^~~~~~~~~~~~~~~~~~~~~~~~