Code seems to work as i expect but
if i declare list not as a pointer i get error
like this
conversion from 'LinkedList<int>*' to non-scalar type 'LinkedList<int>' requested
How to fix this error
Suppose i would like to introduce pointer to the tail node
How should i update it in functions which modify the list
if you have issues with your code, then post the code that is giving you those issues
don't post a code that's different and it hasn't those particular errors
> Suppose i would like to introduce pointer to the tail node
> How should i update it in functions which modify the list
¿what functions would need to keep it updated? ¿how did you manage with `head'?
I tested your code with at the the online shell and it worked fine, even without instantiating your list as an object on the heap.
Here the main() which I used for testing at the online shell:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int main()
{
int k,m,n;
LinkedList<int> L;// = new LinkedList<int>();
srand(time(nullptr));
// cout << "Enter number of nodes"<<endl;
n = 5; //cin>>n;
//cout<<"Enter the upper range of data in nodes" << endl;
m = 10; //cin>>m;
for(k=0;k<n;k++)
L.insertNode(rand()%m);
L.print();
//delete L;
return 0;
}
Here the output:
Head traversal
1 -> 1 -> 4 -> 6 -> 9 -> NULL
Number of nodes on the list :5
Tail traversal
9 -> 6 -> 4 -> 1 -> 1 -> NULL
Number of nodes on the list :5