Home > Back-end >  Dalao people help take a look at this list where there is a problem orz ~
Dalao people help take a look at this list where there is a problem orz ~

Time:02-13

 
# include
# include
# include
# define N 5
Typedef struct stuNode
{
Char ID [15].
Char name [10].
Char sex [4];
Char grade [5].
Char major [20].
Struct stuNode * next;
} stuNode, * stuNodeP;
StuNodeP headStu;
# define LEN sizeof (stuNode)
StuNodeP Create_StuList (int n)
{
int i;
StuNodeP headStu;
StuNodeP p0, p1.
HeadStu=p0=(stuNode *) malloc (LEN);
For (I=1; i <=n; I++)
{
P1=(stuNode *) malloc (LEN);
Printf (" please enter the student's student id, name, gender, class, profession: \ n ");
The scanf (" % s % s % s % s % s ", p1 - & gt; ID, p1 - & gt; The name, p1 - & gt; Sex, p1 - & gt; Grade, p1 - & gt; Major);
P0 - & gt; Next=p;
P0=p;
}
P1 - & gt; Next=NULL;
Return headStu;
}
StuNodeP delete_StuList (stuNodeP headStu, char delID [15])
{
StuNodeP lp=0, p=0;
Lp=headStu;
P=the lp - & gt; Next;
While ((STRCMP (p - & gt; ID, delID)!=0) & amp; & (p - & gt; Next!=NULL))
{
Lp=p;
P=p - & gt; Next;
}
If (STRCMP (p - & gt; ID, delID)==0)
{
Lp - & gt; Next=p - & gt; Next;
Free (p);
}
The else
Printf (" no search to the student, can't delete! \n");
Return headStu;
}
StuNodeP add (stuNodeP headStu, char newID [15])
{
StuNodeP p=headStu, q=headStu - & gt; Next;
StuNodeP newstuNode;
While ((STRCMP (q - & gt; ID, newID) & lt; 0) & amp; & (q - & gt; Next!=NULL));
{
P=p - & gt; Next;
Q=q - & gt; Next;
}
NewstuNode=(stuNode *) malloc (sizeof (LEN));
Strcpy (newstuNode - & gt; ID, newID);
Printf (" please enter the student's student id, name, gender, class, profession: ");
The scanf (" % s % s % s % s % s ", newstuNode - & gt; ID, newstuNode - & gt; The name, newstuNode - & gt; Sex, newstuNode - & gt; Grade, newstuNode - & gt; Major);
If (STRCMP (q - & gt; ID, newID) & lt; 0)
P=q;
NewstuNode - & gt; Next=p - & gt; Next;
P - & gt; Next=newstuNode;
Return headStu;
}
Void show (stuNodeP headStu)
{
Int num=0;
StuNode * p;
P=headStu - & gt; Next;
While (p!=NULL)
{
Printf (" % d: % s, % s, % s, % s, % s \ n ", + + num, p - & gt; ID, p - & gt; The name, p - & gt; Sex, p - & gt; Grade, p - & gt; Major);
P=p - & gt; Next;
}
}
Int main ()
{
StuNodeP head;
Char ID [15].
The head=Create_StuList (N);
Printf (" please input to delete student's student id information: \ n ");
The scanf (" % s ", & amp; ID);
The head=delete_StuList (headStu, ID);
The head=add (headStu, ID);
Show (headStu);
return 0;
}

CodePudding user response:

There is a error,
Triggered the exception: read access rights conflict,
Lp * * * * is nullptr,

CodePudding user response:

Singly linked list data structure on data sort http://bbs.csdn.net/topics/392201633

CodePudding user response:

Thank you teacher ~

CodePudding user response:

 # include 
# include
# include
# define N 5
Typedef struct stuNode
{
Char ID [15].
Char name [10].
Char sex [4];
Char grade [5].
Char major [20].
Struct stuNode * next;
} stuNode, * stuNodeP;
StuNodeP headStu;
# define LEN sizeof (stuNode)
StuNodeP Create_StuList (int n)
{
int i;
StuNodeP headStu;
StuNodeP p0, p1.
HeadStu=p0=(stuNode *) malloc (LEN);
For (I=1; i <=n; I++)
{
P1=(stuNode *) malloc (LEN);
Printf (" please enter the student's student id, name, gender, class, profession: \ n ");
The scanf (" % s % s % s % s % s ", p1 - & gt; ID, p1 - & gt; The name, p1 - & gt; Sex, p1 - & gt; Grade, p1 - & gt; Major);
P0 - & gt; Next=p;
P0=p;
}
P1 - & gt; Next=NULL;
Return headStu;
}
StuNodeP delete_StuList (stuNodeP headStu, char delID [15])
{
StuNodeP lp=0, p=0;

Lp=headStu;
P=the lp - & gt; Next;

Puts (delID);
While (p & amp; & STRCMP (p - & gt; ID, delID)!=0) {
//puts (p - & gt; ID);
Lp=p;
P=p - & gt; Next;
}
if (! P) {
Printf (" no search to the student, can't delete! \n");
Return headStu;
}
Lp - & gt; Next=p - & gt; Next;
Free (p);

/*
While ((STRCMP (p - & gt; ID, delID)!=0) & amp; & (p - & gt; Next!=NULL))
{
Lp=p;
P=p - & gt; Next;
}
If (STRCMP (p - & gt; ID, delID)==0)
{
Lp - & gt; Next=p - & gt; Next;
Free (p);
}
The else
Printf (" no search to the student, can't delete! \n");
*/
Return headStu;
}

/* add orderly, but create a linked list and not according to the order of operation, so it does not guarantee has been meaningful */
StuNodeP add (stuNodeP headStu, char newID [15])
{
StuNodeP p=headStu, q=headStu - & gt; Next;
StuNodeP newstuNode;


NewstuNode=(stuNode *) malloc (sizeof (LEN));
Strcpy (newstuNode - & gt; ID, newID);
Printf (" please enter the student's student id, name, gender, class, profession: ");
The scanf (" % s % s % s % s % s ", newstuNode - & gt; ID, newstuNode - & gt; The name, newstuNode - & gt; Sex, newstuNode - & gt; Grade, newstuNode - & gt; Major);

While (q & amp; & STRCMP (q - & gt; ID, newID) & lt; 0 {
P=p - & gt; Next;
Q=q - & gt; Next;
}

if (! Q) {
P - & gt; Next=newstuNode;
NewstuNode - & gt; Next=NULL;
Return headStu;
}

NewstuNode - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related