This program is my Learning single linked list of the time to write code, so not complete, I hope that you understand the list of the time to play a little help, and welcome all students to discuss technology, to technology to make friends all over the world. I QQ number: 648422746
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>
#definelen (structstaff*) malloc (sizeof (STRUCTSTAFF))
Structstaff
{
CHARNAME[10];
Intsalary;
Structstaff*next;
};
Structstaff*creat ();
Voidprint (structstaff*);
Structstaff*find (structstaff*);
Structstaff*addmessage (structstaff*);
Structstaff*deletemessage (structstaff*);
Structstaff*changemessage (structstaff*);
Main ()
{
Structstaff*head,*p;
Head=creat ();
Print (head);
P=find (head);
Head=addmessage (head);
Head=deletemessage (head);
Head=changemessage (head);
}
Structstaff*creat ()
{
STRUCTSTAFF*HEAD,*P1,*P2;
INTN;
n=0;
Head=null;
P1=len;
printf ("/n) Please type the student's information (including first name, score):/n");
scanf ("%s%d", p1->name,&p1->salary);
while (p1->salary>0)
{
n++;
if (n==1)
HEAD=P1;
Else
p2->next=p1;
P2=P1;
P1=len;
scanf ("/n%s%d", p1->name,&p1->salary);
}
p2->next=null;
Returnhead;
}
Voidprint (Structstaff*head)
{
Structstaff*p;
P=head;
while (P!=null)
{
printf ("/n%s%d", p->name,p->salary);
p=p->next;
}
}
Structstaff*find (Structstaff*head)
{
STRUCTSTAFF*P1;
CHARFINDNAME[10];
P1=head;
printf ("/npleaseinputyoufindname:/n");
scanf ("%s", FindName);
while (P1!=null)
{
if (strcmp (findname,p1->name) ==0)
{
printf ("/n%s%d", p1->name,p1->salary);
RETURNP1;
}
Else
p1=p1->next;
}
if (p1=null)
printf ("/n does not have the information/n for the student you are looking for");
}
Structstaff*addmessage (Structstaff*head)
{
STRUCTSTAFF*P1,*P2;
P1=head;
P2=head;
P1=len;
printf ("N/a Please enter the information you want to add:/n");
scanf ("/n%s%d", p1->name,&p1->salary);
if (head!=null)
{
P2=head;
p1->next=p2;
HEAD=P1;
}
Else
HEAD=P1;
Print (head);
Returnhead;
}
Structstaff*deletemessage (Structstaff*head)
{
STRUCTSTAFF*P1,*P2;
CHARDELETENAME[10];
P1=head;
P2=head;
printf ("/n Delete student's information, type the student's name:/n");
scanf ("%s", deletename);
while (strcmp (deletename,p1->name)!=0)
{
P2=P1;
p1=p1->next;
}
if (strcmp (head->name,p1->name) ==0)
{
head=p1->next;
}
ElseIf (strcmp (deletename,p1->name) ==0)
{
p2->next=p1->next;
}
Free (p1);
Print (head);
Returnhead;
}
Structstaff*changemessage (Structstaff*head)
{
Structstaff*p;
CHARCHANGENAME[10];
P=head;
printf ("/n Modify the student's information, type the student's name:");
scanf ("%s", changename);
while (strcmp (changename,p->name)!=0)
{
p=p->next;
}
printf ("/n the student's information is:%s%d", p->name,p->salary);
printf ("/n please retype the student's information including name, Score:");
scanf ("%s%d", p->name,&p->salary);
printf ("/N All students ' information is as follows:/n");
Print (head);
}