I think I have been going at this all wrong. Let me state the
rquirements:
Write a function called listsize that takes a pointer to start of
linked list and returns number of elements.
Write a main to create linked list of 4,5,3 as value1,value2,value3
and the call the function to calculate the size and print it.
Here is what I have:
#include <iostream>
using namespace std;
struct listrec
{
int value;
struct listrec *next;
};
int listsize(int);
struct listrec *p;
int main()
{
struct listrec e1,e2,e3;
e1.value = 4;
e1.next = &e2;
e2.value = 5;
e2.next = &e3;
e3.value = 3;
e3.next = NULL;
int x =0;
int sum = listsize(&x);
cout << "The list size is " << sum;
system("pause");
return 0;
}
int listsize(int &x)
{
int num=0;
while(*p!= NULL);
{
*p = *p -next;
num++;
}
return num;
}
new error:
26 D: invalid conversion from `int*' to `int'
D: In function `int listsize(int&)':
39 no match for 'operator!=' in '*p != 0'