码迷,mamicode.com
首页 > 其他好文 > 详细

链表的增删查改---增

时间:2020-05-19 12:33:02      阅读:51      评论:0      收藏:0      [点我收藏+]

标签:null   using   char   before   end   strcmp   namespace   string   student   

#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;
}

链表的增删查改---增

标签:null   using   char   before   end   strcmp   namespace   string   student   

原文地址:https://www.cnblogs.com/Mr-Zhao---haolong/p/12915946.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!