1

I'm having trouble while implementing array of link list in c++. I made 2 functions , one insert and display. Can someone help ?

This is the main function

node* a[100],*b,*temp,*temp2;
for(int i=0;i<100;i++)
{

    a[i]=NULL;;
}

insert_node(a,1,143);
display(a,1)

And this is insert function

void insert_node(node **q[100],int pos,int data)
{
node *temp,*temp2;
if(*q[pos]==NULL)
{
    temp=new node;
    temp->next=NULL;
   temp->data=data;
   *q[pos]=temp;
}
else
{
    temp2=*q[pos];
    while(temp2->next != NULL )
    {
        temp2=*q[pos];
        temp2=temp2->next;
    }
    temp=new node;
    temp->next=NULL;
    temp->data=data;
    temp2->next=temp;
}
}

and this is display function

void display(node **q[100], int pos)
{
node * temp;

temp=*q[pos];
cout<<"\n";
while(temp->next != NULL)
{
    cout<<" "<<temp->data;
}
}

It gives error that

error: cannot convert 'node**' to 'node***' for argument '1' to 'void insert_node(node***, int, int)'

error: cannot convert 'node**' to 'node***' for argument '1' to 'void display(node***, int)

1 Answers1

0

Change

void insert_node(node **q[100],int pos,int data)

to

void insert_node(node *q[100],int pos,int data)

and

void display(node **q[100], int pos)

to

void display(node *q[100], int pos)
revelationnow
  • 356
  • 1
  • 7
  • Okay I had to also remove all the de-references and it worked. But can you explain why we changed so ? Don't we need a pointer to pointer while receiving a pointer ? **EDIT : Okay I get it. Thanks a ton :D** – Ujjwal chhabra Mar 15 '17 at 17:57