ok,im now having problems that says that all of the declarations that i included in my private class is being shown as undeclared,along with a whole bunch of other errors.
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 165 166 167 168 169 170 171 172 173 174 175
|
#ifndef LList_h
#define LList_h
#include <iostream>
template<class itemtype>
class llist
{
friend std::ostream& operator<<(std::ostream & , llist<itemtype> &)
private:
{
struct nodetype
{
itemtype item;
nodetype *next;
}
nodetype *first, *last;
}
public:
llist();
void firstinsert(itemtype);
void frontinsert(itemtype);
void endinsert(itemtype);
void inorderinsert(itemtype);
bool search(itemtype);
bool delete();
bool listempty();
itemtype firstitem();
itemtype lastitem();
~llist();
};
#endif
template <class itemtype>
llist llist<itemtype>::llist()
{
first=last=0;
}
template <class itemtype>
void llist<itemtype>::firstinsert(itemtype x)
{
nodetype *first
first= new nodetype;
last= first;
first->item =x;
first->next = 0;
}
template <class itemtype>
void llist<itemtype>::frontinsert(itemtype x)
{
nodetype *newnode;
newnode= new nodetype;
newnode->item =x;
newnode->next=first;
first=newnode;
}
template <class itemtype>
void llist<itemtype>::endinsert(itemtype x)
{
nodetype *last;
nodetype *newnode;
newnode= new nodetype;
newnode->item =x;
newnode->next=0;
*last->next=newnode;
*last=newnode;
}
template <class itemtype>
void llist<itemtype>::inorderinsert(itemtype x)
{
nodetype *cur;
nodetype *prev;
nodetype *newnode;
newnode= new nodetype;
newnode->item =x;
newnode->next=0;
if(x<=first->item)
{
newnode->next=first;
first=newnode;
}
else if (x>=last->item)
{
last->next=newnode;
last=newnode;
}
else
{
prev=first;
cur=first->next;
while(x>cur->item)
{
prev=cur;
cur=cur->next;
}
}
}
template <class itemtype>
bool llist<itemtype>::listempty()
{
return(first==0);
}
template <class itemtype>
itemtype llist<itemtype>::firstitem()
{
return first->item;
}
template <class itemtype>
itemtype llist<itemtype>::firstitem()
{
return last->item;
}
template <class itemtype>
bool llist<itemtype>::search(itemtype x)
{
nodetype *cur;
cur=first;
while ((cur!=0)&&(x!=cur->item))
{
cur=cur->next;
}
return(cur!=null);
}
template <class itemtype>
bool llist<itemtype>::~llist()
{
nodetype *delnode;
while(first!=0)
{
delnode=first;
first=first->next;
delete delnode;
}
}
template <class itemtype>
llist<itemtype>::delete(itemtype x)
{
nodetype *cur, *prev;
prev=null;
cur=first;
while ((cur!=0)&&(x!=cur->item))
{
prev=cur;
cur=cur->next;
if(cur==0)
return 0;
else
{
delnode=cur;
if(prev==0)
{
first=first->next;
}
else
{
prev->next=cur->next;
if (cur==last)
last=prev;
}
delete delnode;
return 1;
}
}
}
std::ostream &operator <<(std::ostream &output,llist<itemtype> &l)
{
llist<itemtype>::nodetype *cur;
cur=l.first;
while(cur!=0)
{
output<<cur->item<<"|";
cur=cur->next;
}
return output;
}
|
8 F:\373\LList.h [Warning] friend declaration `std::ostream& operator<<(std::ostream&, llist<itemtype>&)' declares a non-template function
8 F:\373\LList.h [Warning] (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here) -Wno-non-template-friend disables this warning
8 F:\373\LList.h expected `;' before "private"
17 F:\373\LList.h expected `;' before "public"
24 F:\373\LList.h expected unqualified-id before "delete"
and to sort of boil it down:
F:\373\LList.h In constructor `llist<itemtype>::llist()':
36 F:\373\LList.h `first' undeclared (first use this function)
36 F:\373\LList.h `last' undeclared (first use this function)
F:\373\LList.h In member function `void llist<itemtype>::firstinsert(itemtype)':
41 F:\373\LList.h `nodetype' undeclared (first use this function)
42 F:\373\LList.h `first' undeclared (first use this function)
42 F:\373\LList.h expected `;' before "first"
43 F:\373\LList.h `last' undeclared (first use this function)
F:\373\LList.h In member function `void llist<itemtype>::frontinsert(itemtype)':
50 F:\373\LList.h `nodetype' undeclared (first use this function)
50 F:\373\LList.h `newnode' undeclared (first use this function)
51 F:\373\LList.h `nodetype' has not been declared
53 F:\373\LList.h `first' undeclared (first use this function)
please help me