Trying to make my function that takes in an array and arrayLength and outputs a linked list equivalent to the array.Any help would be greatly appreciated!

 Node* array2List(int A[], int n)
    {
       Node* p;
       Node* q;
       q = NULL;
       for(int i = 0;i<n;i++)
       {
          p = new Node;
          p->val = A[i];setcar(p,A[i]);
          cout << p->val;//just to check if p->val is getting the right values, and it is.
          p->link = q;
          q = p;
       }
       return reverse(p);
    }

I believe line 11 should be p = p->link and you can get rid of lines 4,5 and 12.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.