tshudyb 0 Newbie Poster

I am not sure how to go about writing a function of a generic type that will transfer the data from a linked-list in one array to the linked list in another array.

#ifndef LINKED_LIST
#define LINKED_LIST

template <class T>
class ListNode {
public:
	T name;
	ListNode<T> *next;
	ListNode(T value, ListNode *p = 0) {
		name = value; next = p;
	}
};

template <class T>
class LinkedList {
public:
	LinkedList() {
		head = tail = 0;
	}
	~LinkedList();
	int isEmpty() {
		return head == 0;
	}
	void addToHead(T);
	void addToTail(T);
	T deleteFromHead();
	T deleteFromTail();
	void deleteNode(T);
	bool isInList(T) const;
private:
	ListNode<T> *head, *tail;
};

template <class T>
class arrayE {
private:
	char * hotelName;
	LinkedList<T> list;

public:
	int counter;

	void HotelName();
	void CheckIn(T);
	void CheckOut(T);
	void Transfer(T, int, int);
	void Count(char*);
	void Print(char *);
	void Quit();
};

#endif
#include <iostream>
#include "SLL.h"

template <class T>
void LinkedList<T>::addToHead(T newValue)
{
	head = new ListNode<T>(newValue, head);
	if(tail == 0)
		tail = head;
}
template <class T>
void LinkedList<T>::addToTail(T value)
{
	if(tail != 0) {
		tail->next = new ListNode<T>(value);
		tail = tail->next;
	}
	else head = tail = new ListNode<T>(value);
}
template <class T>
T LinkedList<T>::deleteFromHead() 
{
	T el = head->name;
	ListNode<T> *tmp = head;
	if (head == tail)
		head = tial = 0;
	else head = head->next;
	delete tmp;
	return el;
}
template <class T>
T LinkedList<T>::deleteFromTail()
{
	T el = tail->name;
	if(head == tail) {
		delete head;
		head = tail = 0;
	}
	else {
		ListNode<T> *tmp;
		for (tmp = head; tmp->next != tail; tmp = tmp->next);
		delete tail;
		tail = tmp;
		tail->next = 0;
	}
	return el;
}
template <class T>
void LinkedList<T>::deleteNode(T el)
{
	if(head != 0)
		if(head == tail && el == head->name) {
			delete head;
			head = tail = 0;
		}
		else if(el == head->name) {
			ListNode<T> *tmp = head;
			head = head->next;
			delete tmp;
		}
		else {
			ListNode<T> *pred, *tmp;
			for (pred = head, tmp = head->next;
				tmp != 0 && !(tmp->name == el)
				pred = pred->next, tmp = tmp->next);
			if(tmp != 0) {
				pred->next = tmp->next;
				if(tmp == tail)
					tail = pred;
				delete tmp;
			}
		}
}
template <class T>
bool LinkedList<T>::isInList(T el) const
{
	ListNode<T> *tmp;
	for(tmp = head; tmp !=0 && !(tmp->name == el); tmp = tmp->next;
		return tmp != 0;
}

template <class T>
void arrayE<T>::CheckIn(T value)
{
	list->addToHead(value);
	counter++
}
template <class T>
void arrayE<T>::CheckOut(T value)
{
	list->addToHead(value);
	counter++
}