this the one of example linked list in full program, but i still cant solve it, hope any people there can help me
this quest wee need to answer on "//" sign only, hope please help me, this like one question it will come out in my exam, this question one of linked list in class classified.
#ifndef H_LinkedListType
#define H_LinkedListType
#include <iostream>
#include <cassert>
using namespace std;
template <class type="">
struct nodeType {
Type info;
nodeType<type> *link;
};
template <class type="">
class linkedListIterator {
public:
linkedListIterator();
linkedListIterator(nodeType<type> *ptr);
Type operator*();
linkedListIterator<type> operator++();
bool operator==(const linkedListIterator<type>& right) const;
bool operator!=(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);
}
template <class type="">
class linkedListType {
public:
const linkedListType<type>& operator=
(const linkedListType<type>&);
void initializeList();
bool isEmptyList() const;
void print() const;
int length() const;
void destroyList();
Type front() const;
Type back() const;
virtual bool search(const Type& searchItem) const = 0;
virtual void insertFirst(const Type& newItem) = 0;
virtual void insertLast(const Type& newItem) = 0;
virtual void deleteNode(const Type& deleteItem) = 0;
linkedListIterator<type> begin();
linkedListIterator<type> end();
linkedListType();
linkedListType(const linkedListType<type>& otherList);
~linkedListType();
void reversePrint() const;
protected:
int count; nodeType<type> *first; nodeType<type> *last;
private:
void copyList(const linkedListType<type>& otherList);
void recursiveReversePrint(nodeType<type> *current) const;
};
template <class type="">
bool linkedListType<type>::isEmptyList() const {
return(first == NULL);
}
template <class type="">
linkedListType<type>::linkedListType() { first = NULL;
last = NULL;
count = 0;
}
template <class type="">
void linkedListType<type>::destroyList() {
nodeType<type> *temp; while (first != NULL) { temp = first; first = first->link; delete temp; }
last = NULL; count = 0;
}
template <class type="">
void linkedListType<type>::initializeList() {
destroyList(); }
template <class type="">
void linkedListType<type>::print() const {
nodeType<type> *current;
current = first; while (current != NULL) { cout << current->info << " ";
current = current->link;
}
}
template <class type="">
int linkedListType<type>::length() const {
return count;
}
template <class type="">
Type linkedListType<type>::front() const {
assert(first != NULL);
return first->info; }
template <class type="">
Type linkedListType<type>::back() const {
assert(last != NULL);
return last->info; }
template <class type="">
linkedListIterator<type> linkedListType<type>::begin() {
linkedListIterator<type> temp(first);
return temp;
}
template <class type="">
linkedListIterator<type> linkedListType<type>::end() {
linkedListIterator<type> temp(NULL);
return temp;
}
template <class type="">
void linkedListType<type>::copyList
(const linkedListType<type>& otherList) {
nodeType<type> *newNode; nodeType<type> *current;
if (first != NULL) destroyList();
if (otherList.first == NULL) { first = NULL;
last = NULL;
count = 0;
} else {
current = otherList.first; count = otherList.count;
first = new nodeType<type>;
first->info = current->info; first->link = NULL; last = first; current = current->link;
while (current != NULL) {
newNode = new nodeType<type>; newNode->info = current->info; newNode->link = NULL; last->link = newNode; last = newNode; current = current->link; } }}
template <class type="">
linkedListType<type>::~linkedListType() { destroyList();
}
template <class type="">
linkedListType<type>::linkedListType
(const linkedListType<type>& otherList) {
first = NULL;
copyList(otherList);
}
template <class type="">
const linkedListType<type>& linkedListType<type>::operator=
(const linkedListType<type>& otherList) {
if (this != &otherList) { copyList(otherList);
}
return *this;
}
#endif