Z
zfareed
I have a program that creates a linked list and is required to count
the number of elements in the list. This is what I have thus far.
#include <iostream>
using namespace std;
struct listrec
{
int value;
struct listrec *next;
};
listrec e1,e2,e3;
int listsize(listrec,int&);
struct listrec* temp;
int main()
{
e1.value = 4;
e1.next = &e2;
e2.value = 5;
e2.next = &e3;
e3.value = 3;
e3.next = NULL;
int sum = 0;
cout << "The list size is " << listsize(*temp,sum);
system("pause");
return 0;
}
int listsize(listrec *p,int &num)
{
struct listrec* temp = p;
int num=0;
do{
temp = temp -> next;
num++;
}while(temp!= NULL);
return num;
}
error: `pntr' undeclared (first use this function)
That is my error and I always have problems calling functions.
the number of elements in the list. This is what I have thus far.
#include <iostream>
using namespace std;
struct listrec
{
int value;
struct listrec *next;
};
listrec e1,e2,e3;
int listsize(listrec,int&);
struct listrec* temp;
int main()
{
e1.value = 4;
e1.next = &e2;
e2.value = 5;
e2.next = &e3;
e3.value = 3;
e3.next = NULL;
int sum = 0;
cout << "The list size is " << listsize(*temp,sum);
system("pause");
return 0;
}
int listsize(listrec *p,int &num)
{
struct listrec* temp = p;
int num=0;
do{
temp = temp -> next;
num++;
}while(temp!= NULL);
return num;
}
error: `pntr' undeclared (first use this function)
That is my error and I always have problems calling functions.