Hello. I'm having a bit of trouble with my code.I have worked through most of the issues but I could use a little help. I've been troubleshooting this program for awhile now and I think a set of fresh eyes would help here.
I currently am using CodeBlocks IDE.
Here's my build messages that I get when I try to compile this code:
C:\Users\---\Documents\C++\CCISProject4\main.cpp||In member function 'void CircularLinkedList<ItemType>::printList()':|
C:\Users\---\Documents\C++\CCISProject4\main.cpp|155|error: missing template arguments before '*' token|
C:\Users\---\Documents\C++\CCISProject4\main.cpp|155|error: 'current' was not declared in this scope|
C:\Users\---\Documents\C++\CCISProject4\main.cpp|155|error: 'head' was not declared in this scope|
||=== Build finished: 3 errors, 0 warnings (0 minutes, 0 seconds) ===||
Can anyone point me to what I'm doing wrong here?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#ifndef CIRCULARLINKEDLIST_H
#define CIRCULARLINKEDLIST_H
#include <iostream>
#include <string>
using namespace std;
template <class ItemType>
struct nodeType;
template <class ItemType>
class CircularLinkedList
{
private:
nodeType <ItemType> *listData;
int length;
nodeType <ItemType> *currentPos;
public:
CircularLinkedList()
{
length = 0;
listData = NULL;
}
~CircularLinkedList()
{
makeEmpty();
}
CircularLinkedList(const CircularLinkedList<ItemType> &);
bool operator = (CircularLinkedList<ItemType>);
bool operator == (CircularLinkedList<ItemType>);
void operator < (CircularLinkedList<ItemType>);
void operator > (CircularLinkedList<ItemType>);
bool isFull() const;
int getLength() const;
void retrieveItem(ItemType& item, bool& found);
void insertItem(ItemType item);
void deleteItem(ItemType item);
void resetList();
void printList();
void makeEmpty();
void getNextItem(ItemType &item);
};
#endif
template <class ItemType>
void CircularLinkedList<ItemType>::makeEmpty()
{
nodeType<ItemType>* tempPtr;
while (listData != NULL)
{
tempPtr = listData;
listData = listData->next;
delete tempPtr;
}
length = 0;
}
template <class ItemType>
void CircularLinkedList<ItemType>::retrieveItem(ItemType& item, bool& found)
{
nodeType<ItemType>* location;
location = listData;
found = false;
while( (location != NULL && !found))
{
if(item == location->info)
{
found = true;
item = location->info;
}
else
location = location->next;
}
}
template <class ItemType>
void CircularLinkedList<ItemType>::insertItem(ItemType newItem)
{
nodeType<ItemType>* location;
location = new nodeType<ItemType>;
location->info = newItem;
location->next = listData;
listData = location;
delete location;
length++;
}
template <class ItemType>
void CircularLinkedList<ItemType>::deleteItem(ItemType item)
{
nodeType<ItemType>* location = listData;
nodeType<ItemType>* tempLocation;
if(item == listData->info)
{
tempLocation = location;
listData = listData->next;
}
else
{
while(!(item == (location->next)->info))
location = location->next;
tempLocation = location->next;
location->next = (location->next)->next;
}
delete tempLocation;
length--;
}
template <class ItemType>
bool CircularLinkedList<ItemType>::isFull() const
{
nodeType<ItemType>* ptr;
ptr = new nodeType<ItemType>;
if(ptr == NULL)
return true;
else
{
delete ptr;
return false;
}
}
template <class ItemType>
int CircularLinkedList<ItemType>::getLength() const
{
return length;
}
template <class ItemType>
void CircularLinkedList<ItemType>::resetList()
{
currentPos = listData;
}
template <class ItemType>
void CircularLinkedList<ItemType>::getNextItem(ItemType &item)
{
item = currentPos->info;
currentPos = currentPos->next;
}
template <class ItemType>
void CircularLinkedList<ItemType>::printList()
{
nodeType* current = head;
while(current->link != head)
{
cout << current->info << " ";
current = current->link;
}
cout << current->info << endl;
}
|