📄 lab75.cpp
字号:
// lab75.cpp : Defines the entry point for the console application.
//
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "malloc.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;i<n;i++)
{
s = (struct stu *)malloc(sizeof(struct stu));
p->next = 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!\n");
return(h);
}
void deletelist(struct stu *l,int a)
{
struct stu *p;
while(l->age!=a)
{
p = l;
l = l->next;
}
if(l==NULL)
printf("The record is not exist.");
else
{
p->next = l->next;
printf("Delete successful!\n");
}
}
void insertl(struct stu *li2,int i)
{
struct stu *new1,*p;
int mount=0;
new1=(struct stu *)malloc(sizeof(struct stu));
printf("Please input the information of insert the student: name sex no age \n");
scanf("%s %c %d %d",new1->name,&new1->sex,&new1->no,&new1->age);
for(mount=0;mount<i;mount++)
{
p=li2;
li2=li2->next;
}
p->next=new1;
new1->next=li2;
printf("Insert successfullly\n");
}
void display(struct stu *l1)
{
l1 = l1->next;
while(l1!=NULL)
{
printf("%s %c %d %d\n",l1->name,l1->sex,l1->no,l1->age);
l1 = l1->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);
insertl(s,2);
display(s);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -