Help me resolve the errors below
I get the following warnings:
1 2 3
|
50 50 declaration shadows a field of linkedListForward
60. 57 will never be executed
82. 28 variable 'first' is uninitialized when used here
|
Here is my 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
|
#include<iostream>
#include<cassert>
using namespace std;
struct nodeType
{
int info;
nodeType *link;
};
class linkedListForward
{
public:
nodeType *buildListForward();
nodeType *first, *last, *newNode;
void printList();
int largestElement(nodeType *first) ;
};
nodeType *linkedListForward::buildListForward()
{
int num;
cout<<"Enter a list of integers ending with -999.\n";
cin >> num;
first = NULL;
while(num != -999)
{
newNode = new nodeType;
assert(newNode != NULL);
newNode->info = num;
newNode->link = NULL;
if(first == NULL)
{
first = newNode;
last = newNode;
}
else
{
last->link = newNode;
last = newNode;
}
cin >> num;
}//end while
return first;
}//end buildListForward
int linkedListForward::largestElement(nodeType *first)
{
int max = INT_MIN;
while(first != NULL)
{
if(max < first->info)
max = first->info;
first = first->link;
}
return max;
// }
cout<<endl<<"Largest element in myList is : "<<max <<endl;
}
void linkedListForward::printList()
{
cout<<"Linked list printed out: " <<endl;
nodeType *current;
current = first;
while(current != NULL)
{
cout << current->info << " ";
current = current->link;
}
}
int main()
{
linkedListForward myList;
nodeType *first;
myList.buildListForward();
myList.printList();
myList.largestElement( first);
//{cout <<"LargestElement in myList is: "<<max;}
}
|
The line are actually 49. 60. And 81
Topic archived. No new replies allowed.