链表的增删查改---增
Posted mr-zhao---haolong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了链表的增删查改---增相关的知识,希望对你有一定的参考价值。
#include <iostream>
#include <string.h>
using namespace std;
struct student{
int age;
char name[10];
char sex[5];
student *next;
};
//链表的增删查改---增;
int main(){
cout<<"请输入学生信息:"<<endl;
student c={39,"xiaobai","boy",NULL};
student b={29,"xiaohong","girl",&c};
student a={10,"xiaoming","boy",&b};
student d={18,"keke","boy",NULL};
student *head=&a;
student *before=head;
student *pointer=before->next;
while(before){
if(strcmp(before->name,"xiaohong")==0)
{
d.next=pointer;
before->next=&d;
break;
}
else
before=pointer;
pointer=pointer->next;
}
before=head;
while(before){
cout<<before->age<<"-"<<before->name<<"-"<<before->sex<<endl;
before=before->next;
}
return 0;
}
以上是关于链表的增删查改---增的主要内容,如果未能解决你的问题,请参考以下文章