note.txt

来自「一个学生的信息是:姓名」· 文本 代码 · 共 66 行

TXT
66
字号
#include "stdio.h"
#include "conio.h"
struct stu{
    char name[20];
    char sex;
    int no;
    int age;
    struct stu * next;
}*linklist;
struct stu *creatlist(int n)
{
    int i;
    //h为头结点,p为前一结点,s为当前结点
    struct stu *h,*p,*s;
    h = (struct stu *)malloc(sizeof(struct stu));
    h->next = NULL;
    p=h;
    for(i=0;inext = s;
        printf("Please input the information of the student: name sex no age \n");
        scanf("%s %c %d %d",s->name,&s->sex,&s->no,&s->age);
        s->next = NULL;
        p = s;
    }
    printf("Create successful!");
    return(h);
}
void deletelist(struct stu *s,int a)
{
struct stu *p;
while(s->age!=a)
{
  p = s;
  s = s->next;
}
if(s==NULL)
  printf("The record is not exist.");
else
{
  p->next = s->next;
  printf("Delete successful!");
}
}
void display(struct stu *s)
{
s = s->next;
    while(s!=NULL)
    {
        printf("%s %c %d %d\n",s->name,s->sex,s->no,s->age);
        s = s->next;
    }
}
int main()
{
    struct stu *s;
int n,age;
printf("Please input the length of seqlist:\n");
scanf("%d",&n);
    s = creatlist(n);
    display(s);
printf("Please input the age:\n");
scanf("%d",&age);
deletelist(s,age);
display(s);
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?