Home > Back-end >  Return value type and function value types do not match how to change
Return value type and function value types do not match how to change

Time:09-25

# include
# include
using namespace std;
Typedef int ElemType;//define the data type
Typedef struct Node
{
ElemType data;//store chain table data
Struct Node * next;//next to pointer field, storing the addresses of its successive nodes,
} LinkList;

//head interpolation to create singly linked list
Void CreatList_L (LinkList * & amp; L, ElemType a [], int n)
{
LinkList * s;
int i;
L=(LinkList *) malloc (sizeof (LinkList));//create a head node
L - & gt; Next=NULL;
for (int i=0; i {
S=(LinkList *) malloc (sizeof (LinkList));
S - & gt; Data=https://bbs.csdn.net/topics/a [I];
S - & gt; Next=L - & gt; Next;//s pointed to the next
L - & gt; Next=s;//it singly linked lists to s L header
}
}

//stern interpolation to create singly linked lists
Void CreatList_Tail (LinkList * & amp; L, ElemType a [], int n)
{
LinkList * s * r;
int i;
L=(LinkList *) malloc (sizeof (LinkList));//create a head node
L - & gt; Next=NULL;
for (int i=0; i {
S=(LinkList *) malloc (sizeof (LinkList));
S - & gt; Data=https://bbs.csdn.net/topics/a [I];
R - & gt; Next=s;
R=s;
}
R - & gt; Next=NULL;
}

//by value lookup
Int the Locate (LinkList * L, ElemType e)
{
LinkList * p=L - & gt; Next;
int j=0;
while (p !=NULL & amp; & p-> The data!=e)
{
P=p - & gt; Next;
j++;
}
If (p==NULL)
return 0;
The else
Return j;
}

//before singly linked lists of the ith element insert element x
ElemType int InsElem (LinkList * L, x, int I)
{
int j=0;
LinkList * p=L, * s;
If (I & lt;=0)
return 0;
while (p !=NULL & amp; & J & lt; The first I - I - 1)//find 1 node * p
{
j++;
P=p - & gt; Next;
}
If (p==NULL)
return -1;//not found nodes return 1
The else
{
S=(LinkList *) malloc (sizeof (LinkList));//create a new node
S - & gt; Data=https://bbs.csdn.net/topics/x;//storage element x
S - & gt; Next=p - & gt; Next;
p-> Next=s;
return L;
}
}

CodePudding user response:

ElemType int InsElem (LinkList * L, x, int I)===="" "the return value is an int type
{
int j=0;
LinkList * p=L, * s;
If (I & lt;=0)
return 0;
while (p !=NULL & amp; & J & lt; The first I - I - 1)//find 1 node * p
{
j++;
P=p - & gt; Next;
}
If (p==NULL)
return -1;//not found nodes return 1
The else
{
S=(LinkList *) malloc (sizeof (LinkList));//create a new node
S - & gt; Data=https://bbs.csdn.net/topics/x;//storage element x
S - & gt; Next=p - & gt; Next;
p-> Next=s;
return L;===="returns the list pointer to int does not match the
}

CodePudding user response:

Modify the function definition
!Don't return 1 if the node is not found, returns NULL

CodePudding user response:

To define or change to return ah,,, see what you need, if you need an int, then change to return, if you want to return a pointer to assign a value to use, then to define, into a pointer type, the error returns NULL
  • Related