链接列表数组

时间:2017-03-15 17:35:44

标签: c++ arrays

我在c ++中实现链接列表数组时遇到了麻烦。我做了2个功能,一个插入和显示。有人可以帮忙吗?

这是主要功能

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

    a[i]=NULL;;
}

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

这是插入功能

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;
}
}

这是显示功能

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

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

它给出错误

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 个答案:

答案 0 :(得分:0)

更改

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

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

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

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