linked list linking errors: PLEASE HELP!!! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

linked list linking errors: PLEASE HELP!!!

I asked for help with this once before, but I tried what was suggested and it didn't work, unless I did it wrong. In my template linked list PriorityQueue, I get these linking errors. this assignment is due on monday and I haven't found any answers. I'm desperate!!!!!!!!

Compiling...
PriorityQueue.cpp
QueueTest.cpp
Linking...
QueueTest.obj : error LNK2001: unresolved external symbol "public: __thiscall PriorityQueue::~PriorityQueue(void)" (??1?$PriorityQueue@M@@QAE@XZ)
QueueTest.obj : error LNK2001: unresolved external symbol "public: int __thiscall PriorityQueue::NumAboveElement(float)" (?NumAboveElement@?$PriorityQueue@M@@QAEHM@Z)
QueueTest.obj : error LNK2001: unresolved external symbol "public: int __thiscall PriorityQueue::Search(float)" (?Search@?$PriorityQueue@M@@QAEHM@Z)
QueueTest.obj : error LNK2001: unresolved external symbol "public: void __thiscall PriorityQueue::WriteAllAbove(int)const " (?WriteAllAbove@?$PriorityQueue@M@@QBEXH@Z)
QueueTest.obj : error LNK2001: unresolved external symbol "public: void __thiscall PriorityQueue::WriteAll(void)const " (?WriteAll@?$PriorityQueue@M@@QBEXXZ)
QueueTest.obj : error LNK2001: unresolved external symbol "public: int __thiscall PriorityQueue::getLength(void)const " (?getLength@?$PriorityQueue@M@@QBEHXZ)
QueueTest.obj : error LNK2001: unresolved external symbol "public: void __thiscall PriorityQueue::Pop(void)" (?Pop@?$PriorityQueue@M@@QAEXXZ)
QueueTest.obj : error LNK2001: unresolved external symbol "public: void __thiscall PriorityQueue::Push(float,int)" (?Push@?$PriorityQueue@M@@QAEXMH@Z)
QueueTest.obj : error LNK2001: unresolved external symbol "public: __thiscall PriorityQueue::PriorityQueue(void)" (??0?$PriorityQueue@M@@QAE@XZ)
Debug/Assign2.exe : fatal error LNK1120: 9 unresolved externals
Error executing link.exe.

Assign2.exe - 10 error(s), 0 warning(s)

******************Header File**************************

//***********************************************************************************************
// "PriorityQueue.h"
//
// This is the specification for the linked list ADT implementation
// of the PriorityQueue
//***********************************************************************************************

#include

using namespace std;

template
struct NodeType;

template
class PriorityQueue
{
public:
PriorityQueue();
PriorityQueue(const PriorityQueue& OtherList);
void CopyFrom(const PriorityQueue& OtherList);
void Push(const T newElement,int newPriority);
void Pop();
int getLength() const;
void WriteAll() const;
void WriteAllAbove(int MaxPriority) const;
int Search(const T element);
int NumAboveElement(const T element);
~PriorityQueue();
private:
NodeType* head;
};


******************Source File**************************

//******************************************************************
// "PriorityQueue.cpp"
//
// This is the implementation file for the linked list ADT
// implementation of the PriorityQueue
//******************************************************************

#ifndef PRIORITYQUEUE_H
#define PRIORITYQUEUE_H

#include "PriorityQueue.h"
#include
#include

using namespace std;

template
typedef NodeType* NodePtr;

template
struct NodeType
{
T item;
int priority;
NodePtr link;
};

//******************************************************************

template
PriorityQueue::PriorityQueue()
{
head = NULL;
}

//******************************************************************

template
PriorityQueue::PriorityQueue(const PriorityQueue& OtherList)
{
NodePtr fromPtr;
NodePtr toPtr;

if(OtherList.head == NULL)
{
head = NULL;
return;
}

fromPtr = OtherList.head;
head = new NodeType;
head->item = fromPtr->item;
head->priority = fromPtr->priority;

toPtr = head;
fromPtr = fromPtr->link;
while(fromPtr == NULL)
{
toPtr->link = new NodeType;
toPtr = toPtr->link;
toPtr->item = fromPtr->item;
toPtr->priority = fromPtr->priority;
fromPtr = fromPtr->link;
}
toPtr->link = NULL;
}

//******************************************************************

template
void PriorityQueue::CopyFrom(const PriorityQueue& OtherList)
{
while(head != NULL)
Pop();

NodePtr fromPtr;
NodePtr toPtr;

if(OtherList.head == NULL)
{
head = NULL;
return;
}

fromPtr = OtherList.head;
head = new NodeType;
head->item = fromPtr->item;
head->priority = fromPtr->priority;

toPtr = head;
fromPtr = fromPtr->link;
while(fromPtr == NULL)
{
toPtr->link = new NodeType;
toPtr = toPtr->link;
toPtr->item = fromPtr->item;
toPtr->priority = fromPtr->priority;
fromPtr = fromPtr->link;
}
toPtr->link = NULL;
}

//******************************************************************

template
void PriorityQueue::Push(T newElement, int newPriority)
{
NodePtr currPtr;
NodePtr prevPtr;
NodePtr newNodePtr;

newNodePtr = new NodeType;
newNodePtr->item = newElement;
newNodePtr->priority = newPriority;

prevPtr = NULL;
currPtr = head;
while(currPtr != NULL && newPriority > currPtr->priority)
{
prevPtr = currPtr;
currPtr = currPtr->link;
}

newNodePtr->link = currPtr;
if(prevPtr == NULL)
head = newNodePtr;
else
prevPtr->link = newNodePtr;
}

//******************************************************************

template
void PriorityQueue::Pop()
{
if(head == NULL)
{
cout << "The Queue is empty. Pop not performed.
";
return;
}
cout << "Item " << setprecision(1) << head->item
<< " with priority " << head->priority
<< " has been removed.
";
NodePtr tempPtr = head;
head = head->link;
delete tempPtr;
}

//******************************************************************

template
int PriorityQueue::getLength() const
{
int length = 0;
NodePtr tempPtr = head;
while(tempPtr != NULL)
{
tempPtr = tempPtr->link;
length++;
}
return length;
}

//******************************************************************

template
void PriorityQueue::WriteAll() const
{
NodePtr tempPtr = head;
cout << "
Element Priority
------- --------
";
while(tempPtr != NULL)
{
cout << setw(9) << setprecision(1) << tempPtr->item
<< setw(8) << tempPtr->priority << endl;
tempPtr = tempPtr->link;
}
cout << endl;
}

//******************************************************************

template <class T>
void PriorityQueue::WriteAllAbove(int MaxPriority) const
{
NodePtr tempPtr = head;
cout << "
Element Priority
------- --------
";
while(tempPtr != NULL && MaxPriority >= tempPtr->priority)
{
cout << setw(9) << setprecision(1) << tempPtr->item
<< setw(8) << tempPtr->priority << endl;
tempPtr = tempPtr->link;
}
cout << endl;
}

//******************************************************************

template <class T>
int PriorityQueue::Search(T element)
{
NodePtr tempPtr = head;
while(tempPtr != NULL)
{
if(tempPtr->item == element)
return tempPtr->priority;
tempPtr = tempPtr->link;
}
return -1;
}

//******************************************************************

template
int PriorityQueue::NumAboveElement(T element)
{
int position = 0;
NodePtr tempPtr = head;
while(tempPtr != NULL && tempPtr->item != element)
{
tempPtr = tempPtr->link;
position++;
}
if(tempPtr == NULL)
return -1;
else
return position;
}

//******************************************************************

template
PriorityQueue::~PriorityQueue()
{
while(head != NULL)
Pop();
}

//******************************************************************

#endif

******************Test Program*************************

//******************************************************************
// This is the test program for the PriorityQueue abstract data type
//

//
// Input: Any desired amount of Element and Priority pairs, along
// with the desired operations on the queue
//
// Output: The reuslts of operations supplied with the class
//******************************************************************


#include
#include "PriorityQueue.h"

using namespace std;

void PrintMenu();

int main()
{
int oper, newPri, PrintType, limit, indexFound;
float newEle, searchEle;
PriorityQueue PQ;
PrintMenu();
cout << fixed << showpoint << "--> ";
cin >> oper;
while(oper != 0)
{
if(oper == 1)
{
cout << "Please enter the Element followed by the "
<< "Priority
--> ";
cin >> newEle >> newPri;
while(newPri <=0)
{
cout << "Invalid Priority. Enter new Priority for"
<< " element [" << newEle << "]
--> ";
cin >> newPri;
}
PQ.Push(newEle, newPri);
cout << "--> ";
}
else if(oper == 2)
{
PQ.Pop();
cout << "--> ";
}
else if(oper == 3)
{
cout << "The current Queue Length is " << PQ.getLength()
<< " Elements
--> ";
}
else if(oper == 4)
{
cout << " 1 - Display Entire Queue
2 - Display "
<< "Subset of Queue
--> ";
cin >> PrintType;
if(PrintType == 1)
PQ.WriteAll();
else if(PrintType == 2)
{
cout << " What is the largest Priority desired?
"
<< " --> ";
cin >> limit;
while(limit < 1)
{
cout << "Invalid Priority. Largest Priority "
<< "desired?
--> ";
cin >> limit;
}
PQ.WriteAllAbove(limit);
}
else
cout << " Queue Display Aborted
";
cout << "--> ";
}
else if(oper == 5)
{
cout << " What is the Element to be searched for?
"
<< "--> ";
cin >> searchEle;
indexFound = PQ.Search(searchEle);
if(indexFound == -1)
cout << " Element [" << searchEle << "] not found"
<< "
--> ";
else
cout << " Element [" << searchEle << "] found with"
<< " priority [" << indexFound << "]
--> ";
}
else if(oper == 6)
{
cout << " What is the Element to be searched for?
"
<< "--> ";
cin >> searchEle;
indexFound = PQ.NumAboveElement(searchEle);
if(indexFound == -1)
cout << " Element [" << searchEle << "[ not found"
<< "
--> ";
else
cout << " There are " << indexFound << " elements"
<< " above [" << searchEle << "]
--> ";
}
else
{
PrintMenu();
cout << "--> ";
}
cin >> oper;
}
cout << "Exit. QueueTest deleting list to prevent leaks...
";
return 0;
}

//******************************************************************

void PrintMenu()
// Postcondition: The entire menu is printed for the user
{
cout << "
1 - Push
2 - Pop
3 - Write Queue Length
"
<< "4 - Display Queue
5 - Search Queue
6 - Location "
<< "of Element
0 - Exit
";
}
Sign In or Register to comment.