# # ifndef T3X_H
# define T3X_H
#include
#include
using namespace std;
Struct StuType;
Struct LNode;
Extern LinkList InitLink ();
Extern LinkList LinkInsert (LinkList head, int n);
Extern int LinkDelete (LinkList head, int n);
Extern LinkList LinkLocate (LinkList head, int n);
Extern int PrintAll (LinkList head);
Extern int the Add ();
Extern int ListLength (LinkList head);
# endif
.cpp
# include "t3x. H"
#include
#include
using namespace std;
Struct StuType
{
String num.
string name;
int age;
};
Struct LNode
{
StuType data;
struct LNode *next;
} LNode * LinkList;
LinkList InitLink ()
{LinkList head;
The head=new LinkList;
If (head==NULL)
{
Printf (" \ n application memory space failure ");
}
The head - & gt; Next=NULL;
Return (the head);
}
LinkList LinkInsert (LinkList head, int n)
{
for(int i=0; i
Newnode=new LNode;
Cin> Newnode. Num;
Cin> Newnode. Name;
Cin> Newnode. Age;
Return (the head);
}
Int LinkDelete (LinkList head, int n)
{
LinkList p, q;
P=the head;
for(int i=0; i
Q=p - & gt; Next;
P - & gt; Next=q - & gt; Next;
return 0;
}
LinkList LinkLocate (LinkList head, int n)
{
LinkList p;
P=the head;
for(int i=0; i
The return p - & gt; The data;
}
Int PrintAll (LinkList head)
{
LinkList p=head;
while(p!=NULL)
{
Cout<& lt;" Student number: "& lt; P=p - & gt; Next;
}
return 0;
}
Int the Add ()
{
Cout<& lt;" Please enter the student id, name and professional ";
NewLNode=new LNode;
Cin> NewLNode - & gt; Num.
Cin> NewLNode - & gt; name;
Cin> NewLNode - & gt; age;
return 0;
}
Int ListLength (LinkList head)
{
int n;
While (the head!=NULL)
{
The head=head - & gt; Next;
N=n + 1;
}
return n;
}
Int main ()
{int I, j, n, the func.
LNode data;
LinkList * pdata;
pdata=https://bbs.csdn.net/topics/InitLink ();
Cout<& lt;" Please input to input information about students ";
Cin> n;
for(i=0; i
Cout<& lt;" The student information as follows: "in the singly linked lists & lt;
Printf (" 0. Exit, \ t1 insert information, \ t2 delete information, \ t3 update to specify the names of the students, \ t4 to find specify the student's information, \ t5 output information for all students, \ t6 output the number of students \ n ");
For (j=0;; J++)
{
The scanf (" % d ", & amp; Func);
The switch (func)
{
Case 0:
exit(1);
break;
Case 1:
Cout<& lt;" Please input to the position of the insert information: ";
Cin> i;
Cout<& lt;" Please enter the first "& lt; Cin> Data. Num> Data. Name> Data. The age;
If (LinkInsert (pdata, I))
{cout<& lt;" Insert data success "& lt;
break;
Case 2:
Cout<& lt;" Please input you want to delete the information position: ";
Cin> i;
If (LinkDelete (pdata, I))
{cout<& lt;" Data deleted successful "& lt;
break;
Case 3:
Cout<& lt;" Please input to update the information of position: ";
Cin> i;
data=https://bbs.csdn.net/topics/LinkLocate (pdata, I);
Cout<& lt;" Please enter the replacement name: ";
Cin> Data. The name;
Cout<& lt;" Updated the first "& lt; break;
Case 4:
Cout<& lt;" Please input to locate the position of the information: ";
Cin> i;
data=https://bbs.csdn.net/topics/LinkLocate (pdata, I);
Cout<& lt;" The first "& lt; break;
Case 5:
PrintAll (pdata);
break;
Case 6:
Cout<& lt;" Number of students for "& lt;
}
return 0;
}
Then is always below the mistakes, but don't know how to change
CodePudding user response:
Define the CPP inside the two structure covered. HCodePudding user response:
C + + compiler compiler, compiler header file first, and then compile the CPP source file, in your header files using LinkList, but LinkList is defined in the CPP source file, so the compiler doesn't know LinkList, should put in the CPPstruct StuType
{
String num.
string name;
int age;
};
Struct LNode
{
StuType data;
struct LNode *next;
} LNode * LinkList;
Written at the end of file, if you put the two structures in the CPP statement, please refer to the "prior to class in c + + statement", the hope can help you!
CodePudding user response:
Why such after modified, the first error still exists?
Ps: the program has not changed, just changed the position, from at the end of the CPP file
CodePudding user response:
nullnullnullnullnull